I use OmniGraffle for preparing figures to appear in LaTeX documents. To to this I need to export from OmniGraffle to PDF. Rather than having to remember to export the figure every time I make an edit I have started to automate the process. I think this might be of use to others who use LaTeX and OmniGraffle.
I use latexmk (called through textmate) to produce the PDF version of my documents. Latexmk allows you to add specialised converters for unknown images types. I have added the following to my .latexmkrc file:
The OmniGraffleConverter script (inspired by this script for LyX) looks like:
This script works very well but there is one problem. The script does not leave OmniGraffle in the original state. If the figure was not open then it will be opened, exported and closed, therefore returning to the original state. However, if the figure is open, but the not the front most window, it will be raised. I would like to reset the front most window as the script exits. I have a reference - theOriginalDoc - to the front most document, but I can't work out how to activate it at the end. Any suggestions?
I use latexmk (called through textmate) to produce the PDF version of my documents. Latexmk allows you to add specialised converters for unknown images types. I have added the following to my .latexmkrc file:
Code:
# Converter for .graffle -> .pdf add_cus_dep( 'graffle', 'pdf', 0, 'OmniGraffleConverter'); sub OmniGraffleConverter { system("osascript ~/Library/Scripts/OmniGraffleConverter.scpt `pwd`/$_[0].graffle `pwd`/$_[0].pdf"); }
Code:
on run argv -- check arguments if (count of argv) is not 2 then error "usage OmniGraffleConverter input output" end if set theGraffleFile to POSIX file (item 1 of argv) set theBaseName to do shell script "basename \"" & (item 1 of argv) & "\"" set theOutputFile to POSIX file (item 2 of argv) tell application "OmniGraffle Professional 5" -- construct list of open documents set openDocCount to (the count of documents) set docList to {} if openDocCount > 0 then set theOriginalDoc to (the first document) repeat with i from 1 to number of items in documents set doc to item i of documents copy (name of doc) to the end of docList end repeat end if -- open file try open file theGraffleFile on error activate set theMessage to "Error: couldn't open file " & (item 1 of argv) beep display dialog theMessage buttons {"Ok"} with icon stop error theMessage end try -- export file try save document theBaseName in theOutputFile if docList does not contain theBaseName then close document (theBaseName) end if on error activate set theMessage to "Error: couldn't save file " & (item 1 of argv) beep display dialog theMessage buttons {"Ok"} with icon stop error theMessage end try -- TODO restore front document if openDocCount > 0 then end if end tell end run