Question

I'm using both NSWorkspaceDidActivateApplicationNotification and NSWorkspaceDidLaunchApplicationNotification notifications to know which app the user is interacting with.

The problem is that, if an application is just opened and still launching, I first receive a activate notification, and soon afterwards a launch notification.

Is there any way to know within the activate method that the app is still launching and not yet ready for use? (Still bouncing in the dock)

I see that the ichat sample project by apple does not use the above approach and instead only listens to launch notifications. It then uses kAXApplicationActivatedNotification to add an AXObserver to the app. Is this the preferred way? (And also NSRunningApplications to add an observer to all already loaded apps).

I wanted to keep using just plain simple NSNotifications because I think it may be less memory intensive. (No need to keep an observer around for each and every app loaded).

Was it helpful?

Solution

check the NSRunningApplication object passed in the userinfo of the NSWorkspaceDidActivateApplicationNotification

NSRunningApplication *app = [note.userInfo objectForKey:NSWorkspaceApplicationKey]; 
if(app.isFinishedLaunching) 
    NSLog(@"up");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top