I have a helper application that is active when the GUI app is not. The helper application is posting notifications to [NSUserNotificationCenter defaultNotificationCenter]. I'd like to have the GUI app open when the user activates a notification from the helper. Is there a way to do this?
I'd also prefer that the helper app post notifications with the same name as the main app, but that's less of an issue than getting the didActivateNotification: sent to the right executable.
You could simply open your main app via NSWorkspace in the didActivateNotification:
delegate method:
- (void)userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification:(NSUserNotification *)notification
{
[[NSWorkspace sharedWorkspace] launchApplicationAtURL:[NSURL fileURLWithPath:@"/Applications/TextEdit.app"] options:0 configuration:nil error:nil];
}
This will open the app at the specified URL if it is not running, or bring it to the foreground if it is already open.
An alternative approach would be to register a custom URL scheme in your main app, and use NSWorkspace's openURL. This way you could define a simple action/parameter grammar that triggers different behaviour in your main app.