The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniGraffle General (http://forums.omnigroup.com/forumdisplay.php?f=10)
-   -   Weird issue with AppleScript and "open" function (http://forums.omnigroup.com/showthread.php?t=22315)

einarnn 2011-10-09 02:08 PM

Weird issue with AppleScript and "open" function
 
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[/CODE]

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

Any hints as to how to resolve this problem is will be gratefully received!!

Cheers,

Einar

john.gersh 2011-10-10 05:38 AM

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

einarnn 2011-10-10 07:58 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[/CODE]

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

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.

john.gersh 2011-10-10 11:46 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.

einarnn 2011-10-10 03:00 PM

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.

geneg1 2011-10-10 03:25 PM

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

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

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.

geneg1 2011-10-10 03:35 PM

Creating a new user account makes no difference
 
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.

Brian 2011-10-10 04:06 PM

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

geneg1 2011-10-10 04:26 PM

Reproducing in TextEdit
 
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.

Brian 2011-10-10 05:22 PM

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


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

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