When a user clicks on a Dock icon with the right mouse button (Or a command button + mouse click) on a running application - he can see a Dock menu. Which usually consists of 3 parts:
a list of all opened documents by this application (red), a custom application's part of the menu (yellow) and default items that are added implicitly to all the items (blue).
Here apple explains that we can define these custom items (yellow) by implementing an application delegate's method ‑(NSMenu *)applicationDockMenu:(NSApplication *)sender
, which should return a valid menu (or by defining this Dock menu in Interface Builder).
If you try to open a dock menu for Finder, you can see an unusual menu:
It is unusual because it does not have ordinary items for quitting and "Options" submenu - as any other launched application would have had by default. Instead it has only "Hide".
I am pretty sure an application or a nib file can override this default "system" (blue) part of a Dock menu. Maybe anyone has any idea how that can be achieved?
I am developing a security application that should not be allowed to quit or selected to be launched "at Login", but it should run all the time when the user is logged in (just like Finder, it may be halted only using Force application to Quit or Activity monitor). I have good reasons to want to get rid of it. I am aware that this is not exactly a Mac OS way, but this is not exactly an ordinary application. Have anyone done anything similar?
Thank you
It's pretty simple: create a menu in the nib file, and then connect NSApplication
's dockMenu
outlet to that menu. You can find more information here.
Or you can add menu items to the existing menu via code. You can use -[NSApplication applicationDockMenu:]
to get the existing dock menu and add items programmatically.
The Dock menus are actually put up by the Dock process itself and it just proxies each application's dockMenus, so you can't do anything directly about it.
What would work is: install a Quartz Event Tap, intercept clicks routed to the Dock process, check if it's on your own app's icon, and then put up your own custom menu. Tricky, and not possible at all for a sandboxed app.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With