The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniGraffle Extras (http://forums.omnigroup.com/forumdisplay.php?f=7)
-   -   Omnigraffle script cannot save file (http://forums.omnigroup.com/showthread.php?t=31062)

Dan Thomsen 2013-11-19 05:49 PM

Omnigraffle script cannot save file
 
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

[CODE]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
[/CODE]

fligor 2013-12-17 08:02 AM

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.

Dan Thomsen 2013-12-18 08:25 AM

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?

fligor 2013-12-18 10:47 AM

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 [url]https://developer.apple.com/library/mac/releasenotes/AppleScript/RN-AppleScript/RN-10_8/RN-10_8.html[/url] 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.

Lizard 2013-12-19 02:37 PM

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.

fligor 2013-12-20 04:24 AM

solution!
 
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.

Dan Thomsen 2013-12-20 10:54 AM

Okay this code now works (it is cleaned up a bit as well)

It saves a PDF version of the current canvas in the same directory as the original .graffle file. It takes the file name from the name of the canvas since you might have multiple canvases.

[CODE]tell application "OmniGraffle"
set thedocument to front document
set thePath to the path of the thedocument
set ASTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to "/"
set theDirectory 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
set canvasName to name of originalCanvas as text

# Configure 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

# Save as PDF
set pdfFile to theDirectory & "/" & canvasName & ".pdf"
#display dialog pdfFile
save front document in POSIX file pdfFile

end tell[/CODE]

Dan Thomsen 2013-12-20 11:07 AM

[QUOTE=fligor;128747]
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.[/QUOTE]

This looks like a slick feature, but it isn't working for me. I was able to add the script to the toolbar. However, when I execute it

AppleScript reported the following error:

The file “NEW-export-canvas.scpt” couldn’t be opened because you don’t have permission to view it.

It gives me an option to open the script in the script editor and when I execute it from there it works fine. I don't see anything wrong with the file permissions.

Any clues on how to set the permissions? Any tips on how to change the icon from the standard script icon?

Dan Thomsen 2013-12-24 08:09 AM

After rebooting my machine for other reasons it worked with no change. Probably try just quitting omnigraffle and restarting it.

It is a VERY nice feature!

Ken Case 2013-12-31 07:30 AM

[QUOTE=Dan Thomsen;128751]Any tips on how to change the icon from the standard script icon?[/QUOTE]

You can change the icon in Finder: select the script, then use File->Get Info (Command-I), then click on the icon in the top left corner of the Get Info window. You'll see the script's icon highlight; you can now paste an image over it from another app to change the script's icon.

Hope this helps!


All times are GMT -8. The time now is 02:32 PM.

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