How to make a Finder-like Dock menu?

When the user clicks on the dock icon using the right mouse button (or using the command button + mouse click) in the running application - he can see the Dock menu. This usually consists of 3 parts:

http://i55.tinypic.com/i1for6.png

a list of all open documents of this application (red), the user part of the application (yellow) and default elements that are implicitly added to all elements (blue).

Here apple explains that we can define these custom elements (yellow) by implementing the application delegation method ‑(NSMenu *)applicationDockMenu:(NSApplication *)sender , which should return (or by defining this Dock menu in the Builder interface).

If you try to open the dock menu for Finder, you will see an unusual menu:

Unusual menu

This is unusual because it does not have the usual items to exit and the "Options" submenu, like any other running application by default. Instead, it has only "Hide."

I am sure that the application or the nib file can override this standard "system" (blue) part of the Dock menu. Maybe someone knows how this can be achieved?

I am developing a security application that should not be allowed to log out or choose to run "at logon", but it should be executed all the time when the user is logged in (just like Finder, it can only be stopped using the Force control application exit or activity). I have good reasons to get rid of him. I know that this is not entirely Mac OS, but it is not a very normal application. Has anyone done something like this?

thanks

+4
source share
3 answers

This is pretty simple: create a menu in the nib file, and then connect NSApplication dockMenu to this menu. You can find more information here .

Or you can add menu items to an existing menu using code. You can use -[NSApplication applicationDockMenu:] to get the existing dock menu and add items programmatically.

+2
source

The Dock menu is actually set by the Dock process itself, and it just proxies every dockMenus application, so you can't do anything directly.

It will work: install Quartz Event Tap, intercept clicks redirected to the Dock process, check if it is on your own application icon, and then place your own menu. Tricky, and generally not possible for an isolated application.

+1
source

Instead of messing with the dock menu, can you just add the LSUIElement key in YES to the Info.plist application Info.plist ? This will completely stop your application.

However, this will also prevent the presence of a menu bar.

-1
source

All Articles