On Feb 24, 2011, at 5:36 AM, Christiaan Hofman wrote:
> When I call the "close" command for a document in an external applescript, I have no problem. However, when I run the same script using NSAppleScript from within my app, the document is closed, but the applescript gives an error. The error is -1712, AppleEvent timed out, even though it does return almost immediately, no long wait as I would expect for this error. Makes absolutely no sense. Does AppleScript somehow set a timeout of zero for the close command in this case? What's going on, and can someone perhaps advice as to exactly what's the bug (as it's obviously a bug)?
It's actually not a bug.
When you send a close event to a document, Cocoa Scripting immediately suspends the event, because it may have to do some asynchronous UI (drop a sheet) in order to close the document. When it has finished with that work, it resumes the event with the result.
When you are sending an event external to the app, this all works transparently to you.
However, when a self-send event is suspended, it immediately times out (for obvious reasons.)
How we dealt with this when implementing scripting in BBEdit (which doesn't use Cocoa Scripting) is to recognize self-send events, and handle those separately, with blocking UI. (Modal confirm save panel instead of a sheet.)
If you control both ends, you can adjust the backend to suit. (Or if your script doesn't care about the result, it can cope appropriately.)
If you don't, things get more complicated.
Do not post admin requests to the list. They will be ignored.
Applescript-implementors mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden