Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mac OSX: how to know if app automatically launched at session startup/login?

The users of my app can choose if they want (or not) launch my app at their session startup.

To do this, I use LSSharedFileListRef as described here : How do you make your App open at login?

What I want now is to know if my app has been launched automatically at session startup or via a click on the icon in the dock. Indeed, I have to do different actions in these two cases.

I have got the feeling that it is not possible to use the parameters of the notification in the following delegate method to do this:

- (void)applicationDidFinishLaunching:(NSNotification *)notification

I have seen the following posts but they do not help:

How can I know how my app was launched on Mac OS? => NO ANSWER except some links to other posts which do not help more...

Know if the user launched an app => I don't see how to set/get the "Y" parameter defined in this post

Mac OS X: open application at login, without showing the main window => deals with the fact to hide or not the main window at startup ; what I want is more general: how to know how the app has been launched?

Anybody can help me ?

Thanks !

like image 810
Regis_AG Avatar asked Jan 04 '13 17:01

Regis_AG


1 Answers

If application is set to run at startup, it will run (why not?). So you can save the application start time somewhere. And on the later run (for instance, user quit your application and run again) check if there is this parameter, and if it is later than system boot time, than application this time is not run automatically.

You can check the system boot time via [NSProcessInfo systemUptime]

like image 116
Nickolay Olshevsky Avatar answered Sep 20 '22 23:09

Nickolay Olshevsky