Skip to content

Instantly share code, notes, and snippets.

@Gohla
Last active Nov 9, 2015
Embed
What would you like to do?
Exports OmniGraffle canvasses to .eps and .pdf files for use in latex. Call with ./export.applescript file.graffle generated/
#! /usr/bin/osascript
on replace_string(input, search, replacement)
set oldDelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to search
set textItems to every text item of input
set AppleScript's text item delimiters to replacement
set res to textItems as string
set AppleScript's text item delimiters to oldDelim
return res
end replace_string
on fullpath(location)
tell application "Finder"
set cwd to POSIX path of ((container of (path to me)) as alias)
end tell
return (POSIX path of (cwd & location))
end fullpath
on run (argv)
set sourceFile to fullpath((get (item 1 of argv) as string))
set targetDir to fullpath((get (item 2 of argv) as string))
tell application "OmniGraffle"
open sourceFile
set area type of current export settings to all graphics
repeat with cvs in canvases of front document
# Deduce a filename based on the canvas name
set currentName to name of cvs as text
set cleanName to replace_string(currentName, " ", "_") of me
set canvas of front window to cvs
# Save as both EPS and PDF
set outputFile to targetDir & cleanName & ".eps"
save front document in POSIX file outputFile
set outputFile to targetDir & cleanName & ".pdf"
save front document in POSIX file outputFile
end repeat
end tell
end run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment