Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide the Dock icon

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?

like image 306
papr Avatar asked Mar 06 '09 23:03

papr


People also ask

How do I hide the icons on my Mac Dock?

1) Click the Apple icon to open the menu. 2) In the menu, select System Preferences. 3) Select Dock & Menu Bar from the next window. 4) In the window that opens, select the Automatically hide and select the Dock option.


2 Answers

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

like image 148
epatel Avatar answered Sep 20 '22 06:09

epatel


You can use what is called Activation Policy:

Objective-C

// The application is an ordinary app that appears in the Dock and may // have a user interface. [NSApp setActivationPolicy: NSApplicationActivationPolicyRegular];  // The application does not appear in the Dock and does not have a menu // bar, but it may be activated programmatically or by clicking on one // of its windows. [NSApp setActivationPolicy: NSApplicationActivationPolicyAccessory];  // The application does not appear in the Dock and may not create // windows or be activated. [NSApp setActivationPolicy: NSApplicationActivationPolicyProhibited]; 

Swift 4

// The application is an ordinary app that appears in the Dock and may // have a user interface. NSApp.setActivationPolicy(.regular)  // The application does not appear in the Dock and does not have a menu // bar, but it may be activated programmatically or by clicking on one // of its windows. NSApp.setActivationPolicy(.accessory)  // The application does not appear in the Dock and may not create // windows or be activated. NSApp.setActivationPolicy(.prohibited) 

This should hide the dock icon.

See also

like image 23
Albert Avatar answered Sep 23 '22 06:09

Albert