FROM : Bill Cheeseman
DATE : Thu Dec 16 21:45:28 2004
on 2004-12-16 11:15 AM, Peter Browne at <email_removed> 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_removed>
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
DATE : Thu Dec 16 21:45:28 2004
on 2004-12-16 11:15 AM, Peter Browne at <email_removed> 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_removed>
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
| Related mails | Author | Date |
|---|---|---|
| Peter Browne | Dec 16, 17:15 | |
| j o a r | Dec 16, 17:26 | |
| John Stiles | Dec 16, 17:43 | |
| Bill Cheeseman | Dec 16, 21:45 |






Cocoa mail archive

