Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to launch Apps, from my App, with a custom parameter so I can check whether the app was launched by me?

I'm working on this app that launches other apps. I'm listening to app launches using:

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

And I launch them using (Mail is just an example):

NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:[NSArray arrayWithObject:@"lalalala"], NSWorkspaceLaunchConfigurationArguments, nil];
[[NSWorkspace sharedWorkspace] launchApplicationAtURL:[NSURL URLWithString:@"/Applications/Mail.app"] options:NSWorkspaceLaunchWithoutActivation configuration:dict error:nil];

I did some research, and I saw that you can send an argument when you launch an app (that's why I used the var dict in the code above), but I'm having an issue with this: even using NSWorkspaceLaunchWithoutActivation, the Mail.app is launched and becomes focused with a new composing window. I don't know why it's doing that.

Another thing, if I manage to successfully send a custom argument without focusing the app, how can I check if the app was launched by me (check if the argument is there)?

PS: I'm looking for App Store-ready methods.

like image 910
Pedro Vieira Avatar asked Nov 13 '22 02:11

Pedro Vieira


1 Answers

Send the timestamp (UTC) together with the app name you started to your server or a local file if possible.

Then you can track it.

like image 153
AlexWien Avatar answered Nov 15 '22 12:11

AlexWien