Question: Alright, this title might seem strange, but bear with me. I have an app which can be set on its preferences by the user to launch at login. That means I can expect sometimes the app will be launched by the user (clicking on the Dock/Finder, etc), but some other times the app will be launched automatically by the system, on login.

I would like to show a window when the app is launched by the user, but not when it is launched automatically (as I imagine that would be a pain for the user). How can I do that?

Answer: 
Although it may depend on how you intend to automate the launch of the app, you could use command line arguments to distinguish between system launch vs. user launch.

So, the command line launch might like like this:

```
MyApp -autoLaunch "Y"

```

To parse the command line args in a Cocoa app, you could use `NSUserDefaults` (Yes, [you can](http://perspx.com/archives/parsing-command-line-arguments-nsuserdefaults/)!):

```
if( ![[NSUserDefaults standardUserDefaults] objectForKey:@"autoLaunch"] isEqualToString:"Y"] ) {
    // do something for user initiated launch
}

```
I don't have an exact answer to your question. However, may I suggest that your app should show the window if the window was visible when the user last quit your app?

This may be more in-line with the Mac UI guidelines' suggestion on restoring apps and windows, and is within the user's expectations.

Also, a user who set your app to launch at login will probably understand to close the window and not have it restored the next time, or make the system also hide your app during login.