Search code examples
macosxojolsuielement

OS X - How to detect when app got launched in hidden state at Login?


My background app (LSUIElement mode) briefly shows a window at launch to let the user know that it has launched.

When the app gets launched as a Login item, some users choose to hide this startup window by checking the "Hide" option in the Login Items of the Users & Groups control panel.

While this Hide option effectively hides the startup window, it does also hide any further attempts by my app to show its window(s) unless it makes itself the front (active) application, which is usually not desired due to the nature of this app.

Therefore, I need to learn if my app was launched in this hidden mode so that it can bring itself to front briefly.

(I don't like to activate the app always at launch because it causes a slight flicker that I like to avoid with normal (i.e. unhidden) launches.)

I've also checked out Detect that os x app was launched as login item?, but since applicationWillBecomeActive: does not get called at all for LSUIElement apps unless they activate themselves, that doesn't help me here.


Solution

  • In your applicationDidFinishLaunching method, check [NSApp isHidden].