The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniGraffle Extras (http://forums.omnigroup.com/forumdisplay.php?f=7)
-   -   Automated PDF export for use with latexmk -- Applescript help wanted (http://forums.omnigroup.com/showthread.php?t=11803)

ady 2009-04-01 01:33 PM

Automated PDF export for use with latexmk -- Applescript help wanted
 
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 [URL="http://www.phys.psu.edu/~collins/software/latexmk-jcc/"]latexmk[/URL] (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]
The OmniGraffleConverter script (inspired by [URL="http://wiki.lyx.org/uploads/LyX/MacOSX/og-export.scpt"]this[/URL] script for LyX) looks like:
[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[/CODE]

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?


All times are GMT -8. The time now is 07:13 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.