views:

1483

answers:

2

I want to make a preference for hiding the Dock icon and showing an NSStatusItem. I can create the StatusItem but I don't know how to remove the icon from Dock. :-/

Any ideas?

+9  A: 

I think you are looking for the LSUIElement in the Info.plist

LSUIElement (String). If this key is set to “1”, Launch Services runs the application as an agent application. Agent applications do not appear in the Dock or in the Force Quit window. Although they typically run as background applications, they can come to the foreground to present a user interface if desired.

See a short discussion here about turning it on/off

epatel
+1  A: 

If you want to make it a user preference then you can't use UIElement. UIElement resides in the application bundle you shouldn't edit any of the files in the app bundle as this will invalidate the bundles signature.

The best solution I've found is based on this excellent article . My solution is based on the comment by Dan. In short, There's no way to do this with Cocoa, but it is possible with a tiny bit of Carbon code.

The article also suggests making a helper app that handles the dock icon exclusively. The main app then starts and kills this app depending on the users preferences. This approach strikes me as being more robust than using the Carbon code, but I haven't tried it yet.

Benedict Cohen