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).

有帮助吗?

解决方案

check the NSRunningApplication object passed in the userinfo of the NSWorkspaceDidActivateApplicationNotification

NSRunningApplication *app = [note.userInfo objectForKey:NSWorkspaceApplicationKey]; 
if(app.isFinishedLaunching) 
    NSLog(@"up");
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top