Created
December 7, 2017 21:13
-
-
Save mtnygard/881e2aecb44cd2ab66a4c708fc0b53c7 to your computer and use it in GitHub Desktop.
Omnigraffle automation script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- Convert a single document | |
| -- on process_cli_item(source_file) | |
| set source_file to "/Users/mtnygard/tmp/adjacency-diagram.graffle" | |
| try | |
| do shell script "open -a 'OmniGraffle' " & source_file | |
| delay 2 | |
| tell application id "com.omnigroup.OmniGraffle7" | |
| set area type of current export settings to entire document | |
| open POSIX file source_file as alias | |
| repeat with canvasIndex from 1 to count of canvases of front document | |
| set myCanvas to canvas canvasIndex of front document | |
| set canvas of front window to myCanvas | |
| set filename to "/tmp/" & (name of front document) & "-" & canvasIndex & ".svg" | |
| log "Saving canvas " & canvasIndex & " named '" & (name of canvas of front window) & "' as " & filename | |
| save front document as "public.svg-image" in POSIX file filename | |
| end repeat | |
| close front document | |
| end tell | |
| on error error_message | |
| tell application "Finder" | |
| activate | |
| display dialog error_message buttons {"Cancel"} default button 1 giving up after 120 | |
| end tell | |
| end try | |
| --end process_cli_item | |
| --on run argv | |
| -- process_cli_item(item 1 of argv) | |
| --end run |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| tell current application | |
| do shell script "open -a 'OmniGraffle' /Users/mtnygard/tmp/adjacency-diagram.graffle" | |
| --> "" | |
| end tell | |
| tell application "OmniGraffle" | |
| set area type of current export settings to entire document | |
| get POSIX file "/Users/mtnygard/tmp/adjacency-diagram.graffle" | |
| --> error number -1728 from POSIX file "/Users/mtnygard/tmp/adjacency-diagram.graffle" | |
| open alias "Macintosh HD:Users:mtnygard:tmp:adjacency-diagram.graffle" | |
| --> document id "ilfBQrMRQpa" | |
| count every canvas of document 1 | |
| --> 2 | |
| get canvas 1 of document 1 | |
| --> canvas id 3 of document id "ilfBQrMRQpa" | |
| set canvas of window 1 to canvas id 3 of document id "ilfBQrMRQpa" | |
| get name of document 1 | |
| --> "adjacency-diagram" | |
| get name of canvas of window 1 | |
| --> "modules-with-details" | |
| (*Saving canvas 1 named 'modules-with-details' as /tmp/adjacency-diagram-1.svg*) | |
| save document 1 as "public.svg-image" in file "Macintosh HD:private:tmp:adjacency-diagram-1.svg" | |
| --> error number -10000 | |
| end tell | |
| tell application "Finder" | |
| activate | |
| display dialog "OmniGraffle got an error: AppleEvent handler failed." buttons {"Cancel"} default button 1 giving up after 120 | |
| --> error number -128 | |
| Result: | |
| error "Finder got an error: User canceled." number -128 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment