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 General
FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
Weird issue with AppleScript and "open" function Thread Tools Search this Thread Display Modes
I have some scripts that automate the export of multi-canvas files, but the scripts seem to fail on the "open" call. Specifically, they hang. I can replicate the problem with a simple script I found on the forums here:

Code:
set myDocument to (choose file with prompt "Select an Omnigraffle file")
tell application "OmniGraffle Professional 5"
	set oDoc to open alias myDocument
	set numCanvas to count of canvases of oDoc
end tell
The event/reply log for running this script is:

Code:
tell application "AppleScript Editor"
	choose file with prompt "Select an Omnigraffle file"
		--> alias "Macintosh HD:Users:einarnn:Droplets:cca-visualization.graffle"
end tell
tell application "OmniGraffle Professional 5"
	open alias (alias "Macintosh HD:Users:einarnn:Droplets:cca-visualization.graffle")
Result:
error "OmniGraffle Professional 5 got an error: AppleEvent timed out." number -1712
Any hints as to how to resolve this problem is will be gratefully received!!

Cheers,

Einar
 
There's a clue in the log. File choosers return an alias reference, not a file reference. The error comes from trying to dereference an alias alias (no such animal).

Setting the open line to "set oDoc to open myDocument" seems to do the trick.

I'm not sure why you got a timeout error. When I ran the script, I got

Code:
Can’t get alias (alias \"<myDisk>:<me>:Desktop:Untitled.graffle\")." number -1728 from alias (alias "<myDisk>:Users:<me>:Desktop:Untitled.graffle")

Last edited by john.gersh; 2011-10-10 at 07:10 AM..
 
My mistake. I tried adding in the alias while debugging and I get the same result with or without the alias, namely:

Code:
tell application "AppleScript Editor"
	choose file with prompt "Select an Omnigraffle file"
		--> alias "Macintosh HD:Users:einarnn:Documents:Work:eEdge:acl-stuff.graffle"
end tell
tell application "OmniGraffle Professional 5"
	open alias "Macintosh HD:Users:einarnn:Documents:Work:eEdge:acl-stuff.graffle"
Result:
error "OmniGraffle Professional 5 got an error: AppleEvent timed out." number -1712
And I can also try to open the file directly by name, which gives me this result:

Code:
tell application "OmniGraffle Professional 5"
	open "Macintosh HD:Users:einarnn:Documents:Work:eEdge:acl-stuff.graffle"
Result:
error "OmniGraffle Professional 5 got an error: AppleEvent timed out." number -1712
Note that in each case, the file opens successfully. The problem is just that my script is hosed as the script never gets the result.

Last edited by einarnn; 2011-10-10 at 08:04 AM..
 
I don't get the error, so I can't help much. I can induce the error by opening a large document within a very short with-timeout block, but the default timeout is two minutes, so I doubt that's the problem.
 
Thanks for trying. Anyone from the dev team able to tell me why I might not get a reply to a simple task such as opening a file? The file opens ok and can be edited, etc., so the basic functionality is fine. And the moire complex scripting after that that manipulates the canvases and so on is fine. All just ruined by what seems like a simple issue.

BTW, I'm on Lion and OmniGraffle Pro 5.3.4. I may try earlier versions to see if the problem is more recent.
 
Same issue, OmniGraffle Pro 5.3.4 on OS X 10.7.1. Here is my AppleScript, as basic as possible:

Code:
tell application "OmniGraffle Professional 5"
	open "Bengal:Users:gene:Desktop:Test.graffle"
end tell
OmniGraffle opens the file just fine, but the AppleScript never gets control back. Clicking Stop in the Script Editor does nothing. Actually quitting OmniGraffle pops up this error in Script Editor:

Code:
error "OmniGraffle Professional 5 got an error: Connection is invalid." number -609
I've tried completely deleting OmniGraffle (including Preference files etc.) and reinstalling with no change in behaviour. I've tried a few different test files, including a completely blank one and one with just a single square shape. Same results.

This worked fine until (I believe) I upgraded to Lion. I've tried switching off Resume functionality in System Preferences > General to no effect.

I would love a workaround for this, or even some indication about whether others are seeing this problem.
 
I just tried creating a new OS X user account to see whether the problem persists when logged in as the brand new user, and it makes no difference. Same problem.
 
I can reproduce what you're seeing on my Lion machine. I get the same results when I tell TextEdit to open a document using a similar script, though. ("Connection is invalid".)

This feels like an AppleScript-on-Lion bug...
 
I can sporadically reproduce this in TextEdit as well, although I can't seem to find the pattern. Some (blank) RTF documents open fine, others hang just like OmniGraffle, but only the FIRST time I try to open them. If I then quit TextEdit and run the script again they open fine. Very strange.

I can't reproduce the problem at all in Pages.

It very well could be an AppleScript bug in Lion, but does that mean there is no way currently to open a document in OmniGraffle using AppleScript? That would kill a number of important workflows for me. Any sort of workaround, even a crazy hacky one, would be appreciated.
 
Oh, interesting - I didn't notice the multiple-tries angle. I wonder if it's related to the files' "last opened" date - the first time I tested with TextEdit, I tried an existing file that had been sitting on my desktop for a while. In that case, TextEdit returned a "The document “<foo>” could not be opened. You don’t have permission." message.

I chalked that up to the Versions feature of OS X - it locks files that haven't been modified recently. Created a new test file, pointed the script at that, then got the results you described and went from there.

Okay, just tested with a different not-edited-in-a-while TextEdit document. Script fails when pointed at the script, then starts working if I open the file once via the Finder.

It's possible that this approach will fail if you throw a Graffle document that has been saved as a file package at it, but it appears to work correctly in the case of flat file Graffle docs. (My not-modified-recently docs on this machine appear to all be the latter type.)

Code:
set thecommand to "open Users/UserName/Desktop/FileName.graffle"

do shell script thecommand
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
"Next Action Starts Today" Issue kray OmniFocus 1 for Mac 16 2011-02-03 05:39 PM
Weird dates... "today" is wrong date --> 2059, 2084 etc.! electroglodyte OmniFocus 1 for Mac 0 2009-11-03 09:39 AM
Issue using AppleScript "activate" command chucksense OmniFocus Extras 2 2008-02-10 07:10 AM


All times are GMT -8. The time now is 05:26 PM.


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