Re: AppleScriptability Meets NSOperation
Re: AppleScriptability Meets NSOperation
- Subject: Re: AppleScriptability Meets NSOperation
- From: Jerry Krinock <email@hidden>
- Date: Mon, 29 Mar 2010 16:34:06 -0700
On 2010 Mar 29, at 14:30, has wrote:
> The Apple Event Manager supports suspend and resume
Great tip, has. I searched and found
Cocoa Scripting Guide
How Cocoa Applications Handle Apple Events
Suspending and Resuming Apple Events and Script Commands
In there, it looks like -suspendExecution and -resumeExecutionWithResult: have been provided for my situation exactly. (I am using Cocoa Scripting and NSScriptCommand.)
And it appears that we have solved the problem. But since I couldn't find any sample code using -suspendExecution or -resumeExecutionWithResult:, I shall describe this so I can find it in the list archives next time I forget :)
In my subclass' implementation of performDefaultImplementation:,
[[SSYOperationQueue mainQueue] setScriptCommand:self] ;
[self suspendExecution] ;
In the first line, I stash the command away in an ivar for later, which is necessary because -suspendExecution causes -currentCommand to subsequently return nil.
Then in my asynchronous completion routine,
NSScriptCommand* scriptCommand = [[SSYOperationQueue maenQueue] scriptCommand] ;
if (!ok) {
[scriptCommand setScriptErrorNumber:errorValue] ;
[scriptCommand setScriptErrorString:errorString] ;
}
[scriptCommand resumeExecutionWithResult:nil] ;
Seems to work perfectly, although it's kind of spooky how it works. Maybe they're setting up a sleeping thread for me behind the scenes.
And thank you very much has!! You really kept me from making a big mistake today.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden