How to prevent the app from automatically open a window when launched?

186 views Asked by At

I am developing a OS X app and want it to run without dock icon but with a icon in the menubar. I have added the menubar utility and tried to set the following code in applicationDidFinishLaunching:

[NSApp setActivationPolicy:NSApplicationActivationPolicyAccessory];

It works well, except that the app will still show the window when launched. How to prevent this? I can't set the LSUIElement in Info.plist because I want this behavior to be changeable in the runtime.

Thanks in advance!

Edit

It seems that the Visible At Launch is unchecked by default... I am using storyboard so I created a new project, choose Main.storyboard -> Window Controller Scene -> Window, and found it unchecked, but the window will still open automatically.

image (cannot post it directly with <10 reputation)

0

There are 0 answers