Skip to content

Instantly share code, notes, and snippets.

@arthurlevy
Created September 17, 2015 12:11
Show Gist options
  • Save arthurlevy/0c69387d28e70cbd554d to your computer and use it in GitHub Desktop.
Save arthurlevy/0c69387d28e70cbd554d to your computer and use it in GitHub Desktop.
this is an applescript that converts each canvas of an Omnigraffle file into an eps file. Useful for latex integration. Each eps file name is the canvas name. Based on an original idea by Stephen Millard http://www.thoughtasylum.com/blog/2014/4/30/export-all-canvases-in-omnigraffle.html
on run argv
set input to item 1 of argv
--Choose the output folder. Script ends if cancelled
set cwd to do shell script "pwd"
set strOutputDirectory to (get POSIX file (cwd) as string)
set strOutputDirectory to strOutputDirectory & ":"
set fullinput to strOutputDirectory & input
--Drop the file extension
set strOmniGraffleFileNameNoExtension to remove_extension(input)
--Export each canvas
tell application "OmniGraffle Professional 5"
activate
open file fullinput
set objOmniGraffleFile to front document
set strOmniGraffleFileName to name of objOmniGraffleFile as string
--Initialise
set objOmniGraffleFile to front document
set canvas of front window to canvas 1 of objOmniGraffleFile
set intCanvasCount to count of canvases of objOmniGraffleFile
--Iterate through each canvas and export it to the specified folder
--Files saved in eps format
repeat with intCurrentCanvasID from 1 to intCanvasCount
set canvas of front window to canvas intCurrentCanvasID of objOmniGraffleFile
set currentCanvas to canvas of front window
set strOutputFilePath to strOutputDirectory & name of currentCanvas & ".eps" as string
save objOmniGraffleFile as "eps" in (strOutputFilePath)
end repeat
quit
end tell
end run
-- Remove file extension (from http://www.macosxautomation.com/applescript/sbrt/)
on remove_extension(this_name)
if this_name contains "." then
set this_name to ¬
(the reverse of every character of this_name) as string
set x to the offset of "." in this_name
set this_name to (text (x + 1) thru -1 of this_name)
set this_name to (the reverse of every character of this_name) as string
end if
return this_name
end remove_extension
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment