Move OmniGraffle Package to Flat Format
Hey all, I wanted to share a useful script if you have a bunch of OmniGraffle files that are saved as Automatic or Package format to Flat. This makes them more Windows friendly especially if you store the files on OneDrive. Execute this script using Mac’s Script Editor. Select a folder that contains the OmniGraffle Documents or Stencils. This script will go through each document, open it, convert it, save it, close it. This script will also go into any subdirectories from your selected root folder. Special thanks to Christian Y. from the OmniGroup team for its initial creation.
# Original script created by Christian Y. (Support Human) in the OmniGroup
# for the VMware Design Team - 2019
# Version 1.0
property errorList : "" # Used to build a list of files with errors
on run
set errorList to "" # Reset the error list for each run
tell application "Finder"
set sourceFolder to choose folder with prompt "Please select a folder containing OmniGraffle files:"
set foundItems to (items of sourceFolder) as alias list
my getFilesToProcess(foundItems)
end tell
if errorList is not "" then
display alert "An error occurred trying to process the following files:" message errorList
return errorList
end if
end run
on getFilesToProcess(foundItems)
tell application "Finder"
set filesToProcess to {}
repeat with anItem in foundItems
set fileExt to name extension of anItem
if kind of anItem is "folder" then
set folderContents to (items of anItem) as alias list
my getFilesToProcess(folderContents)
else if fileExt is "graffle" or fileExt is "gstencil" or fileExt is "gtemplate" then
copy anItem to end of filesToProcess
end if
end repeat
my processFiles(filesToProcess)
end tell
end getFilesToProcess
on processFiles(graffleFiles)
repeat with aFile in graffleFiles
tell application "OmniGraffle"
try
open aFile
delay 0.6
tell application "System Events" to tell process "OmniGraffle"
set frontmost to true
delay 0.5
# Handle potential alerts or prompts
try
click button "OK" of sheet 1 of window 1
delay 0.5
end try
try
click button "Edit in Place" of sheet 1 of window 1
delay 0.5
end try
# Access "Document" settings in "Inspectors" menu
click menu item "Document" of menu "Inspectors" of menu bar item "Inspectors" of menu bar 1
try
# First attempt: Sidebar hidden
tell pop up button 1 of scroll area 2 of splitter group 1 of window 1
click
delay 0.5
click menu item "Save as flat file" of menu 1
end tell
on error
# Alternate attempt: Sidebar visible
tell pop up button 1 of scroll area 3 of splitter group 1 of window 1
click
delay 0.5
click menu item "Save as flat file" of menu 1
end tell
end try
end tell
tell front document
save
delay 0.5
close
end tell
on error
tell application "Finder"
set filename to name of aFile
set parentFolder to name of container of aFile
set errorList to errorList & "- " & parentFolder & "/" & filename & return
end tell
end try
end tell
end repeat
end processFiles