Mac Dock icon contextual menus?

Is it possible to add contextual menus to the app icon on the Mac Dock? I know other development systems have this capability.

I would like to add a “Quit” menu to the Icon. I have disabled Quit in the application because it sometimes exits for no apparent reason. This is a reminder type app and should always be running. But I have to KILL it to reboot computer.

Quit is already part of the right click contextual menu of the dock icon.


Of course, the Quit MenuItem (as said by Michel) appears only if the application is running…

So, don’t do as I’ve done yesterday: test on non running icon(s)… :slight_smile:

The Quit menu on the icon on the dock does not function when Quit is disabled in the app. I need a generic dock icon menu item called “Quit Now” or some other name. When clicked the handler will terminate the app.

When the dock icon is clicked, the App.HandleAppleEvent is triggered.

You could either try to reinstate the Quit menu option there, or pop a contextual menu there.

Please check MBS Xojo Plugins.
We have an example “Dock menu with ApplicationDelegate” coming with our plugins with our MBS Xojo MacCocoa Plugin.

1 Like

See blog entry:

Dock Menu for Cocoa in Real Studio

See the picture?

Today I spend a lot of time working on a NSApplicationDelegateMBS class. This class gives you more than 20 application related events including a dockmenu event. There you can build your menu to be displayed in the dock. The event fires everytime the menu is about to be shown, so you can add menu items there dynamically.

As you see we can have all the typical menu features like separators, checkmarks or submenus.

This will be available with 11.2pr5 plugins later tonight (or tomorrow). For Carbon applications, you can use our existing CarbonApplicationEventsMBS class.

Problem solved.
I just added the Quit to application File Menu and set the my global Boolean variable AllowQuit back to true before calling Quit.

FileQuit Menu Handler:
AllowQuit = True
Return True

CancelClose Event Handler:
If AllowQuit = False Then
Return True //don’t quit

Why so? It should be asked to quit like other apps, even with the Quit menu item disabled/removed when the Mac restarts or shuts down.

Return not(AllowQuit)

With CancelClose returning True, nothing short of Force Quit from the Activity Monitor will kill my app.

What will understand your user when (s)he will be there ?
(that is if he knows about Activity Monitor)

This is not a commercial app. It for my own use. It reminds me to standup and move around every hour on the hour.

It is not for sale and is not going to the Apple App Store.

Ah, yes, if you additionally chose to return true in CancelClose, your choice is rather explicit.

Yes, it does exactly what I wanted it to do. Prevent the app from closing except when I want it to!

Forum for Xojo Programming Language and IDE. Copyright © 2021 Xojo, Inc.