0

Is there any way to tell if a Cocoa application, such as Safari, has finished launching and able to respond? I know it's easy to do using delegates within the actual code but that isn't possible for what I'm doing.

Thanks

  • What platform, Mac OS X or iPhone? – Adam Rosenfield Feb 15 '09 at 00:53
  • Well that's the thing... I posted it in Cocoa but I am actually not trying to find a Cocoa solution, just a way to tell if a Cocoa app has successfully launched –  Feb 15 '09 at 03:09
  • Tell if a Cocoa app has successfully launched? Normally if you can click things on the interface, it means awakeFromNib has finished and the app has finished launching. Is there more specifics you are able to give out to help us give a better answer? – Joel Levin Feb 15 '09 at 04:41
  • JXA example: https://stackoverflow.com/a/49560860/199296 – Mat Gessel Jan 24 '21 at 23:55

1 Answers1

8

Check out NSWorkspace and NSWorkspaceDidLaunchApplicationNotification. Something like this:

[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(appDidLaunch:) name:NSWorkspaceDidLaunchApplicationNotification object:nil]

The NSNotification object passed to the specified method will contain information about what application launched, its path, etc. For example:

- (void)appDidLaunch:(NSNotification*)note
{
    NSLog(@"app launched: %@", [note userInfo]);
}

EDIT: this is for desktop cocoa applications only - I'm fairly sure this is impossible in Cocoa Touch. Just clarifying that.

Joel Levin
  • 2,878
  • 1
  • 21
  • 13