The Omni Group
These forums are now read-only. Please visit our new forums to participate in discussion. A new account will be required to post in the new forums. For more info on the switch, see this post. Thank you!

Go Back   The Omni Group Forums > OmniGraffle > OmniGraffle Extras
FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
Automated PDF export for use with latexmk -- Applescript help wanted Thread Tools Search this Thread Display Modes
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:
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");
}
The OmniGraffleConverter script (inspired by this 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
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?
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Applescript to export to visio countdrachma OmniGraffle Extras 0 2011-05-19 03:51 AM
Wanted: AppleScript Guru BwanaZulia OmniFocus Extras 3 2010-06-06 05:43 AM
Feature request: automated HTML export to webdav pteichman OmniFocus 1 for Mac 2 2008-07-22 03:19 PM
html export using AppleScript? kaan OmniPlan General 3 2007-02-26 10:03 AM
Applescript to save and export as pdf brab OmniGraffle General 0 2006-08-10 12:20 AM


All times are GMT -8. The time now is 04:36 PM.


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