Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add/remove application icon from dock at runtime?

Tags:

macos

cocoa

dock

Is there a public Apple API which allows you to remove an application's dock icon at runtime? I have tried substituting an empty view with zero size via NSApplication's dockTile, but that simply erases the dock icon without reclaiming its space and launch indicator. I also know about the LSUIElement parameter in an application's info.plist, but this value is only evaluated on launch. It is not a runtime parameter.

like image 698
ctpenrose Avatar asked Nov 29 '11 20:11

ctpenrose


People also ask

How do I remove app icon from Mac Dock?

Remove an item from the Dock: Drag the item out of the Dock until Remove is shown. Only the alias is removed; the actual item remains on your Mac. If you accidentally remove an app icon from the Dock, it's easy to put it back (the app is still on your Mac). Open the app to make its icon appear again in the Dock.


1 Answers

It's a one way street: You can set your app to NSUIElement to hide the dock icon, then call [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular]; to show it in the dock, but once it's there you can't remove it. So you could make the dock icon user-configurable, but you'd have to relaunch the app to hide the icon.


EDIT

You can call setActivationPolicy:NSApplicationActivationPolicyProhibited to hide dock-icon again – user1592530 Sep 18 '12 at 14:21

The comment is right. Works two ways nowadays – Daij-Djan Dec 24 '12 at 11:46


like image 65
Francis McGrew Avatar answered Sep 18 '22 19:09

Francis McGrew