If you're on 10.6 or later:

- (void)applicationWillTerminate:(NSNotification *)aNotification
{
       NSRunningApplication* helperApp = [NSRunningApplication
runningApplicationsWithBundleIdentifier:@"bundle.id"];
       [helperApp terminate];
}

Sadly, you can't send a terminate command if you're helper app is
sandboxed, so if you have to sandbox -- you'd likely need to reverse
the process.
Your helper app gets the NSRunningApplication object of your main app,
then observes the terminated property of it.
When you are notified of it terminating, you terminate yourself.

Another alternative, use the SMLoginItemsSetEnabled to launch and
terminate your helper app.

Don't think that was what the API was intended actually for, but when
you're stuck in a sandbox, you gotta make due with cheap plastic
shovel that you find in it.



On Thu, Jul 12, 2012 at 10:27 AM, Robert Martin
<robmar...@frontiernet.net> wrote:
> The best way? I have no idea… This is what I do, and it works.
>
> I store the path to my helper app in 'path', and do the following when my app 
> is about to quit:
>
>
> //---------------------------------------------------------------------
> - (void)applicationWillTerminate:(NSNotification *)aNotification
> //---------------------------------------------------------------------
> {
>         [super applicationWillTerminate:aNotification];
>
>         AppleEvent tAppleEvent, tReply;
>         AEBuildError tAEBuildError;
>         ProcessSerialNumber currentProcessPSN;
>         NSNumber *psnHi = nil;
>         NSNumber *psnLo = nil;
>
>         NSArray * runningApps = [[NSWorkspace sharedWorkspace] 
> launchedApplications];
>
>         for(NSDictionary * appInfo in runningApps){
>                 if( [path isEqualToString:[appInfo 
> objectForKey:@"NSApplicationPath"]] ){
>                         psnHi = [appInfo 
> objectForKey:@"NSApplicationProcessSerialNumberHigh"];
>                         psnLo = [appInfo 
> objectForKey:@"NSApplicationProcessSerialNumberLow"];
>                         break;
>                 }
>         }
>
>         if(psnHi == nil) return;
>
>         currentProcessPSN.highLongOfPSN = [psnHi unsignedIntegerValue];
>         currentProcessPSN.lowLongOfPSN = [psnLo unsignedIntegerValue];
>
>         OSStatus result = AEBuildAppleEvent( kCoreEventClass, 
> kAEQuitApplication, typeProcessSerialNumber, &currentProcessPSN,
>                                                                               
>   sizeof(ProcessSerialNumber), kAutoGenerateReturnID, kAnyTransactionID, 
> &tAppleEvent, &tAEBuildError,"");
>         result = AESend( &tAppleEvent, &tReply, kAEAlwaysInteract+kAENoReply, 
> kAENormalPriority, kNoTimeOut, nil, nil );
> }
>
>
> --Rob
>
>
> On Jul 12, 2012, at 12:33 PM, Jerry Krinock <je...@ieee.org> wrote:
>
>> What is the best way to make a helper app quit when the associated main app 
>> quits (or crashes)?  No harm will be done if it keeps running for a minute 
>> or so.
>>
>> Thanks,
>>
>> Jerry Krinock
>
>
> _______________________________________________
>
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>
> 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:
> https://lists.apple.com/mailman/options/cocoa-dev/unmarked%40gmail.com
>
> This email sent to unmar...@gmail.com



-- 
Mark Munz
unmarked software
http://www.unmarked.com/

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to