Snippet: How to check if app runs auto-launched

To check if a Mac OS X app has been launched at login, I use this code:

BOOL autolaunched = ([[[NSProcessInfo processInfo] arguments] count]);

The number of arguments returned by [NSProcessInfo processInfo] is not documented to be different in case of an auto-launch, compared to a user-initiated launch, but it works.

Update July 30, 2012: The approach described above doesn’t work anymore with OS X 10.8 or later. For an alternative approach please see my Detecting Launch At Login Revisited blog post.