On 1 Feb 2012, at 14:29, Ken Thomases wrote: > On Feb 1, 2012, at 1:20 AM, Gerriet M. Denkmann wrote: > >> I tried: >> >> - (void)applicationWillBecomeActive:(NSNotification *)aNotification >> { >> (void)aNotification; >> >> NSRunningApplication *currentApplication = [ NSRunningApplication >> currentApplication ]; >> NSString *bundleIdentifier = currentApplication.bundleIdentifier; >> NSLog(@"%s current: %@",__FUNCTION__, bundleIdentifier); >> >> NSWorkspace *sharedWorkspace = [ NSWorkspace sharedWorkspace ]; >> NSArray *runningApplications = [ sharedWorkspace runningApplications ]; >> for( NSRunningApplication *ru in runningApplications ) >> { >> if ( ru.isActive ) >> { >> NSString *bundleIdentifier = ru.bundleIdentifier; >> NSLog(@"%s active: %@",__FUNCTION__, bundleIdentifier); >> }; >> }; >> } >> >> But both the currentApplication and the active one is our app (NOT the >> previously active one). >> >> Although the name of the notification is applicationWillBecomeActive it acts >> more like >> applicationIsAlreadySomehowActiveAndWIllBecomeFullyActiveRealSoonNow. > > Well, remember that this is Cocoa responding to an event delivered from the > system. Events are delivered asynchronously. The system can't afford to > wait for an app to respond to an event before moving on. > > There is bound to be an interval of time between when the system changed > which app is active and when Cocoa actually acts on the event it received > because of that change.
Yes, I understand this. The good news is: in applicationWillFinishLaunching the active app (not the currentApplication) is still the previously active app. Using this, together with your suggestion of watching Carbon events, I now have a perfect solution. Thanks for your help. Thanks also to Lee Ann Rucker for suggesting using the app delegate methods. Kind regards, Gerriet. _______________________________________________ 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