How to start App with no Window and without Icon in Dock?

I am currently working on an Mac OS X 10.7 and higher app that uses the “LSBackgroundOnly” property to start faceless.
If i add my app to the Mac OS X startup items/apps and checkmark the “do not show on start” i want to be able to show a Window of my app, but Window.Show does not show the window.
If i start the app manually and call the Window.Show event, it displays the Window.

What am i doing wrong here, please? :slight_smile:

Damn, i can’t find a solution on my own :slight_smile:
I even tried to handle it with my MBS Plugins (NSWindowMBS) but it won’t work…

When you check the “Hide” checkbox for login items OSX will hide your app after it launches as if a user went to the application menu, and pulled down to Hide. I believe in obj-c you can use [NSApp activateIgnoringOtherApps:YES] to jump to the front and unhide your app, however I’m too new to Xojo to know what it’s equivalent would be.

On a second note, wouldn’t unhiding your app when the user specifically asked for it to hide be anti-user friendly?

Use LSUIElement instead of LSBackgroundOnly.

Not always. In my case, the app starts hidden and will do online checks of multiple items. The user must be able to open a Window to manage those items (add, remove, …) occasionally.

Oops, i already used LSUIElement. LSBackgroundOnly was a copy&paste error here… :slight_smile:

Thank you Eli.

In that case I wouldn’t use the system Hide function. Have your app start with no windows to do the online checks, and then present a window if you need to manage them. That way, if the user determines they want the app hidden so they can take care of it later you aren’t intruding :slight_smile:

There is a newer way to set your application to launch on login, it’s rather complicated as it requires your application to be Sandboxed and a helper application stored in your bundle.

Not to thread jack, but I would be very interested in more information about this.

My main target is to have an app without an app icon in the dock. And if i think twice about it, i should have asked “How to remove app from Dock in Mac OS X 10.7+?” :slight_smile:

Thank you Tim. This way in combination with

<key>NSUIElement</key> <string>1</string>
in the info.plist of it’s bundle, makes my app behave the way it want it. :slight_smile:

[quote=79733:@Scott Crick] Sam Rowlands There is a newer way to set your application to launch on login, it’s rather complicated as it requires your application to be Sandboxed and a helper application stored in your bundle.

Not to thread jack, but I would be very interested in more information about this.[/quote]

Now you can :slight_smile:

Alrighty - I’ll see what I can do.

Sasha: Did you find out how to remove the dock app icon?

No, i am using the info.plist solution.

<key>NSUIElement</key> <string>1</string>

and i start my App without a Window in the App Properties.

I am now automating it using a Post Build Script for OS X only:

Dim App As String = CurrentBuildLocation + "/""" + CurrentBuildAppName + ".app""" Call DoShellCommand("/usr/bin/defaults write " + App + "/Contents/Info ""NSUIElement"" 1")

BTW: I am doing the same for making my App retina enabled :wink:

Dim App As String = CurrentBuildLocation + "/""" + CurrentBuildAppName + ".app""" Call DoShellCommand("/usr/bin/defaults write " + App + "/Contents/Info ""NSHighResolutionCapable"" YES")

1 Like

Sascha, thank you for posting an elegant way to update the info.plist file which saves from editing it manually :slight_smile:

So am I correct in thinking that the following code ONLY causes the app to start with the dock icon hidden? :

Dim App As String = CurrentBuildLocation + "/""" + CurrentBuildAppName + ".app""" Call DoShellCommand("/usr/bin/defaults write " + App + "/Contents/Info ""NSUIElement"" 1")

Thanks.

[quote=97132:@Richard Summers]So am I correct in thinking that the following code ONLY causes the app to start with the dock icon hidden? :

Dim App As String = CurrentBuildLocation + "/""" + CurrentBuildAppName + ".app""" Call DoShellCommand("/usr/bin/defaults write " + App + "/Contents/Info ""NSUIElement"" 1")

Thanks.[/quote]

Yep. Tried it. No dock icon.

Thanks.