Re: Quitting one application from within another
Re: Quitting one application from within another
- Subject: Re: Quitting one application from within another
- From: Bill Cheeseman <email@hidden>
- Date: Thu, 16 Dec 2004 15:45:28 -0500
on 2004-12-16 11:15 AM, Peter Browne at email@hidden wrote:
> Hi, I'm wondering if it's possible to terminate an application from
> within another. I know you can launch applications etc by using the
> NSSharedWorkspace methods, but I haven't come across anything similar
> for terminating that application when it's no-longer needed. Any ideas?
Here's a generic Cocoa method to create a Quit Apple event and send it. It
hard-codes the target application's creator code (a four-character OSType)
because in my application I only want to quit a specific companion
application. For greater generality, add your own routines to get the
creator code of any application.
- (void)stopOtherApp {
OSType signature = 'XXXX'; // put a real creator code here
NSAppleEventDescriptor *applicationSpecifier =
[NSAppleEventDescriptor descriptorWithDescriptorType:typeApplSignature
bytes:&signature length:sizeof(OSType)];
NSAppleEventDescriptor *quitApplicationAppleEvent =
[NSAppleEventDescriptor appleEventWithEventClass:kCoreEventClass
eventID:kAEQuitApplication targetDescriptor:applicationSpecifier
returnID:kAutoGenerateReturnID transactionID:kAnyTransactionID];
AppleEvent *quitApplicationAppleEventPtr = (AEDesc
*)[quitApplicationAppleEvent aeDesc];
if (quitApplicationAppleEventPtr) {
AESendMessage(quitApplicationAppleEventPtr, NULL, kAENoReply,
kAEDefaultTimeout);
}
}
--
Bill Cheeseman - email@hidden
Quechee Software, Quechee, Vermont, USA
http://www.quecheesoftware.com
PreFab Software - http://www.prefab.com/scripting.html
The AppleScript Sourcebook - http://www.AppleScriptSourcebook.com
Vermont Recipes - http://www.stepwise.com/Articles/VermontRecipes
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden