Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Notify when App quits



Wow,
That seems to be working,
except does it work with command line applications?
I tried but to no avail, but maybe I tested incorrectly, does that only work with .app apps

Thanks,
Matt

On Mar 3, 2004, at 10:31 AM, Manfred Lippert wrote:

I was looking into this,
will registering for a notification center like this inform me? Cause
it is not working so far.
And what type of apps will it inform me on?

[[NSNotificationCenter defaultCenter] addObserver:self

selector:@selector(NotifyMe:)

name:@"NSApplicationWillTerminateNotification" object:nil];

Is this wrong?

I think the name @"NSApplicationWillTerminateNotification" is wrong. If you use the predefined string NSWorkspaceDidTerminateApplicationNotification (defined in NSWorkspace.h) it will work as expected:

[[[NSWorkspace sharedWorkspace] notificationCenter]
addObserver:self
selector:@selector(applicationDidTerminate:)
name:NSWorkspaceDidTerminateApplicationNotification
object:nil];

In your selector "applicationDidTerminate:" you could e.g. do the following:

- (void)applicationDidTerminate:(NSNotification *)notification {
if ([[[notification userInfo] objectForKey:@"NSApplicationName"] isEqualToString:@"Safari"]) {
NSLog(@"Safari has quit!");
}
}

All terminating apps will be notified to you.

Regards,
Mani
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


References: 
 >Notify when App quits (From: Matt Jaffa <email@hidden>)
 >Re: Notify when App quits (From: Sherm Pendley <email@hidden>)
 >Re: Notify when App quits (From: Matt Jaffa <email@hidden>)
 >Re: Notify when App quits (From: Manfred Lippert <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.