Convert OmniGraffle Package Format 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/Package format and want to convert them all to Flat. This makes them more Windows friendly especially if you are storing 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 the root folder you select. 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 : "" -- This is needed so that the sub-routine can build a list of files should  there be any errors

on run
set errorList to "" -- Needed to reset the list from the last time the script was 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 occured 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

try -- Click OK if you get a prompt about missing fonts or similar messages
click button "OK" of sheet 1 of window 1
delay 0.5
end try

try -- Click "Edit in Place" documnet in the prompt that appears when opening stencil or template files outside of the sandbox
click button "Edit in Place" of sheet 1 of window 1
delay 0.5
end try

click menu item "Document" of menu "Inspectors" of menu bar item "Inspectors" of menu bar 1

try -- First attempt, which works if the left-hand sidebar is 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, which works if the left-hand sidebar is showing

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

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.