• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Quitting one application from within another
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

References: 
 >Quitting one application from within another (From: Peter Browne <email@hidden>)

  • Prev by Date: Re: Wrapping an Interactive Unix Executable (update)
  • Next by Date: Re: WindowProxyIconBug
  • Previous by thread: Re: Quitting one application from within another
  • Next by thread: Search Panel
  • Index(es):
    • Date
    • Thread