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

Omnigraffle script cannot save file Thread Tools Search this Thread Display Modes
I have a simple script that exports the current canvas to a PDF file in the same directory as the .graffle file. It is very useful for putting figures in svn for those that don't have omnigraffle.

The problem is when moving from omnigraffle 5 pro to OG 6pro the script doesn't work. If I export the file by hand using the menu systems, then the script works. Even if I remove the pdf file!

Did some sort of set up command change in the dictionary? What can I do to get this script to work in OG 6 pro?

Here is the script

tell application "OmniGraffle"
	set thedocument to front document
	#set thePath to POSIX path of the folder of thedocument
	set thePath to the path of the thedocument
	set ASTID to AppleScript's text item delimiters
	set AppleScript's text item delimiters to "/"
	set newName to (text items 1 through -2 of thePath) as text
	set AppleScript's text item delimiters to ASTID
	# Save the original canvas for restoration
	set originalCanvas to canvas of front window
	# Confgure the output type to all graphics
	# Which will be interpreted as "current canvas" in PDF and EPS files
	set area type of current export settings to all graphics
	set currentName to name of originalCanvas as text
	# this assumes a good canvance name for the file
	#set cleanName to replace_string(currentName, " ", "_") of me
	set cleanName to currentName
	# Save as PDF
	set outputFile to newName & "/" & cleanName & ".pdf"
	#display dialog outputFile
	save front document in outputFile
end tell
I am having the same problem. I hadn't figured out the part where you could save it with the script if you did it by hand. I verified that does work, until you stop and restart OmniGraffle Pro 6. Then it can't save again.

If anyone has had any luck making this work again, please let me know. I also checked and OmniGraffle is running as me, and I have write permissions on the directory. Exporting by hand works fine every time.
I am wondering if it is a Maverick thing where the OS is cacheing the access to the file. So once the app opens it, it knows it is allowed. If the app restarts, you have to cache the access again.

Does anyone know if maverick impacts applescript and permissions?
I got a note back from the helpful folks that answer support mail at Omni. if you add a line the prompts you for the place to save it, it works fine. This has to do with sandboxing, and Apple's rules about what you can do from a sandboxed application. If I save my graffle file inside the Data directory inside OmniGraffle 6's Container (in my ~/Library), then my script works 100%, and can write the files with no effort.

So far I haven't found a way to do this outside the special sandbox area, and as far as I can tell, this is a deliberate security choice on Apple's part.

I found a reference on this page to using a fileURL type instead of a string type for the path, which may help, but I'm a novice at AppleScript and haven't yet figured out how to do that to see if it helps.
Asking for the folder of the front document is (as far as I understand it) not going to be allowed by sandboxing.

If you can replace the commented-out line with a specific path, e.g.
set thePath to POSIX file "/Users/sam/Documents/ExportedGraffles"

that may work better. I haven't tested to see if

"~/Documents/ExportedGraffles" would work so that you can share it with other users.
I wasn't having any problems getting the file path information, I could toss it into a display dialog and see that it was there.

With much thanks to Paul, one of the Support Humans, and the unnamed engineer he got info from, my script is working again.

It required avery minimal change. I had the following two lines:

save first document in pdfFile
save first document in jpgFile

and the change that made it work is

save first document in file pdfFile
save first document in file jpgFile

where pdfFile and jpgFile are the full POSIX path/file name info

Apparently the comment on the upgrade page from Apple about not using strings to save into just means you have to specify that it's a file.

Also, he said that if you move your scripts from ~Library/Scripts to ~/Library/Application Scripts/com.omnigroup.omnigraffle6 (you’ll have to create the folder) you have the added benefit that not only should it work everywhere in the file system that you can edit your toolbar in OmniGraffle and add the scripts right into the toolbar. I haven't tried it yet, but that sounds handy.

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

All times are GMT -8. The time now is 10:15 PM.

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