Re: Any nice way to quit a background/helper app?
Re: Any nice way to quit a background/helper app?
- Subject: Re: Any nice way to quit a background/helper app?
- From: "Sean McBride" <email@hidden>
- Date: Sat, 10 Jan 2009 12:07:51 -0500
Stephen J. Butler (email@hidden) on 2009-01-10 11:18 AM said:
>> Is there a way to quit a background app, other than having NSTask send a
>> unix 'kill' ?
>
>Yeah: you can call the function kill(). man 2 kill
That's not a 'nice way', as requested in the subject. :)
The nice way is to send a quit AppleEvent, which you can do like so:
static OSStatus SendQuitAppleEventToProcess (ProcessSerialNumber psn)
{
OSStatus err = paramErr;
NSAppleEventDescriptor* applicationDesc = [NSAppleEventDescriptor
descriptorWithDescriptorType:typeProcessSerialNumber
bytes:&psn
length:sizeof(psn)];
if (applicationDesc) {
NSAppleEventDescriptor* quitAppAppleEvent = [NSAppleEventDescriptor
appleEventWithEventClass:kCoreEventClass
eventID:kAEQuitApplication
targetDescriptor:applicationDesc
returnID:kAutoGenerateReturnID
transactionID:kAnyTransactionID];
AppleEvent* quitApplicationAppleEventPtr = (AEDesc*)[quitAppAppleEvent
aeDesc];
if (quitApplicationAppleEventPtr) {
AppleEvent replyEvent;
err = AESendMessage (quitApplicationAppleEventPtr, &replyEvent,
kAEWaitReply, kAEDefaultTimeout);
if (!err) {
AEDisposeDesc (&replyEvent);
}
}
}
return err;
}
You can usually get a psn event for 'background apps'. See
GetProcessForPID(). There's also KillProcess() if it does not respond
to the quit event.
Sean
_______________________________________________
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