# Is there no way to disable the MacOS Quit Command?

**URL:** <https://forum.juce.com/t/is-there-no-way-to-disable-the-macos-quit-command/53143>\
**Category:** MacOSX and iOS\
**Created:** [September 26, 2022, 6:24am UTC](https://forum.juce.com/t/is-there-no-way-to-disable-the-macos-quit-command/53143 "2022-09-26T06:24:17Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![stephenk](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/stephenk/32/15198_2.png) [@stephenk](https://forum.juce.com/u/stephenk)\
**Post date:** [September 26, 2022, 6:24am UTC](https://forum.juce.com/t/is-there-no-way-to-disable-the-macos-quit-command/53143/1 "2022-09-26T06:24:17Z")

</div>

I would like to be able to disable the Mac’s Quit command when I have a “modalish” dialog up, such as a non-native file browser (in a GUI App). So far, this seems to be impossible. I’ve tried everything including hacking JUCE code.

(I am using the ApplicationCommandManager, MenuBarModel, etc.)

I’m talking about the Quit item that shows up at the bottom of the “Apple Menu” (next to the real apple icon menu) that gets put there by default when you use a global Mac Menu Bar, and has “Services”, “Hide” etc.

This seems to be hard-coded in at an extremely low level. Even if I comment out everything in the JUCE source code related to `StandardApplicationCommandIDs::quit` (in an attempt to remove the Quit command, just so I can see where it’s coming from) it still shows up. Has anyone found a way to disable this?

---

<div class="post-metadata">

**Author:** ![nicolasdanet](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/nicolasdanet/32/56_2.png) [@nicolasdanet](https://forum.juce.com/u/nicolasdanet)\
**Post date:** [September 26, 2022, 7:31am UTC](https://forum.juce.com/t/is-there-no-way-to-disable-the-macos-quit-command/53143/2 "2022-09-26T07:31:09Z")

</div>

Overriding the `systemRequestedQuit` function of the App should block it, isn’t it?

```auto
void systemRequestedQuit() override
{
    DBG ("?");
}

```

By the way I probably misread your question.

---

<div class="post-metadata">

**Author:** ![kerfuffle](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/kerfuffle/32/11805_2.png) [@kerfuffle](https://forum.juce.com/u/kerfuffle)\
**Post date:** [September 26, 2022, 8:12am UTC](https://forum.juce.com/t/is-there-no-way-to-disable-the-macos-quit-command/53143/3 "2022-09-26T08:12:08Z")

</div>

I don’t know the answer to your question, but why is this something you want to do? Seems very user unfriendly.

---

<div class="post-metadata">

**Author:** ![stephenk](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/stephenk/32/15198_2.png) [@stephenk](https://forum.juce.com/u/stephenk)\
**Post date:** [September 26, 2022, 2:31pm UTC](https://forum.juce.com/t/is-there-no-way-to-disable-the-macos-quit-command/53143/4 "2022-09-26T14:31:34Z")

</div>

> [@nicolasdanet](#):
>
> Overriding the `systemRequestedQuit` function of the App should block it, isn’t it?

Yes, I can block it from executing. But I would rather disable the command so that the user cannot select it. Instead the possibility exists and he selects it, and then you must play the SytemAlert or something and do nothing.

> [@kerfuffle](#):
>
> I don’t know the answer to your question, but why is this something you want to do? Seems very user unfriendly.

Is it? It seems standard behaviour on a lot of MacOS software, when a modal is up, most menu commands (if not all) are disabled. For example, just checking now:  
Photoshop: Open File dialog: All menu commands deactivated including EVERYTHING on the Apple Menu.  
MS Word: Open File dialog: nearly all menu commands deactivated including Quit on the Apple Menu.  
MS Excel: Open File dialog: nearly all menu commands deactivated including Quit on the Apple Menu.  
FireFox: Open File dialog: entire Mac Menu bar disappears except for Apple Menu, and Quit is disabled.

I can also find some that don’t disable the Quit item… but since I’m porting an app that used to work that way, I wanted to be able to disable the Quit command.

---

<div class="post-metadata">

**Author:** ![kerfuffle](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/kerfuffle/32/11805_2.png) [@kerfuffle](https://forum.juce.com/u/kerfuffle)\
**Post date:** [September 26, 2022, 3:35pm UTC](https://forum.juce.com/t/is-there-no-way-to-disable-the-macos-quit-command/53143/5 "2022-09-26T15:35:57Z")

</div>

Interesting, it looks like a lot of apps do this indeed. But lots of apps also don’t. Apparently menu commands are automatically disabled when modal dialogs are shown, so it seems not all apps show the Open File dialog using `[panel runModal]`. IIRC modal loops were removed from JUCE 7 (or was it 6?).

---

<div class="post-metadata">

**Author:** ![stephenk](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/stephenk/32/15198_2.png) [@stephenk](https://forum.juce.com/u/stephenk)\
**Post date:** [September 26, 2022, 3:41pm UTC](https://forum.juce.com/t/is-there-no-way-to-disable-the-macos-quit-command/53143/6 "2022-09-26T15:41:53Z")

</div>

Yes, it is not recommended to use modal anymore (#if JUCE\_MODAL\_LOOPS\_PERMITTED  
). And I’m actually not. In my app and plugins, I simulate modal by installing dialogs as a child component over the entire MainComponent, blocking interaction with the rest of it. I don’t use the ModalComponentManager.

And I have successfully created the behavior of disabling all menu commands when such a “modalish” dialog is up, with the exception of the Apple Menu.

---

<div class="post-metadata">

**Author:** ![asimilon](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/asimilon/32/4235_2.png) [@asimilon](https://forum.juce.com/u/asimilon)\
**Post date:** [September 26, 2022, 3:47pm UTC](https://forum.juce.com/t/is-there-no-way-to-disable-the-macos-quit-command/53143/7 "2022-09-26T15:47:16Z")

</div>

> [@stephenk](#):
>
> with the exception of the Apple Menu.

This was [fixed already](https://forum.juce.com/t/extra-macos-menu-items-to-respect-disabled-flag/37276) (but I didn’t get a chance to test it personally, been a while since working on the codebase that needed it). It probably won’t help with the Quit item though.

---

<div class="post-metadata">

**Author:** ![stephenk](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/stephenk/32/15198_2.png) [@stephenk](https://forum.juce.com/u/stephenk)\
**Post date:** [September 26, 2022, 3:50pm UTC](https://forum.juce.com/t/is-there-no-way-to-disable-the-macos-quit-command/53143/8 "2022-09-26T15:50:53Z")

</div>

> [@asimilon](#):
>
> This was [fixed already](https://forum.juce.com/t/extra-macos-menu-items-to-respect-disabled-flag/37276) (but I didn’t get a chance to test it personally, been a while since working on the codebase that needed it). It probably won’t help with the Quit item though.

Yeah, I’ve been able to disable items I add, such as “Show About Box”, but no way to get at the Quit item. 🙁

---

<div class="post-metadata">

**Author:** ![asimilon](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/asimilon/32/4235_2.png) [@asimilon](https://forum.juce.com/u/asimilon)\
**Post date:** [September 26, 2022, 3:55pm UTC](https://forum.juce.com/t/is-there-no-way-to-disable-the-macos-quit-command/53143/9 "2022-09-26T15:55:44Z")

</div>

Sounds like a legit feature request then. Something like `virtual bool isQuitMenuItemEnabled()` in `MenuBarModel` perhaps.

---

<div class="post-metadata">

**Author:** ![stephenk](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/stephenk/32/15198_2.png) [@stephenk](https://forum.juce.com/u/stephenk)\
**Post date:** [September 26, 2022, 4:02pm UTC](https://forum.juce.com/t/is-there-no-way-to-disable-the-macos-quit-command/53143/10 "2022-09-26T16:02:32Z")

</div>

Yes. In the meantime, I’m going to try to hack something together to see if I can make this happen. I’ve just now figured out that this is the code that creates the Apple Menu. Interestingly enough, it is installed as a SubMenu in the first menu that you provide. So for example, my MenuBarModel has a File Menu as the first menu, so this installs the AppleMenu as a submenu in the File Menu.

Problem is, I don’t speak Swift or Objective C or whatever this is. 🙄 ☺

```auto
    static void createStandardAppMenu (NSMenu* menu, const String& appName, const PopupMenu* extraItems)
    {
        if (extraItems != nullptr && JuceMainMenuHandler::instance != nullptr && extraItems->getNumItems() > 0)
        {
            for (PopupMenu::MenuItemIterator iter (*extraItems); iter.next();)
                JuceMainMenuHandler::instance->addMenuItem (iter, menu, 0, -1);

            [menu addItem: [NSMenuItem separatorItem]];
        }

        // Services...
        NSMenuItem* services = [[[NSMenuItem alloc] initWithTitle: translateMenuName ("Services")
                                                           action: nil keyEquivalent: nsEmptyString()] autorelease];
        [menu addItem: services];

        NSMenu* servicesMenu = [[[NSMenu alloc] initWithTitle: translateMenuName ("Services")] autorelease];
        [menu setSubmenu: servicesMenu forItem: services];
        [NSApp setServicesMenu: servicesMenu];
        [menu addItem: [NSMenuItem separatorItem]];

        createMenuItem (menu, TRANS("Hide") + String (" ") + appName, @selector (hide:), nsStringLiteral ("h"));

        [createMenuItem (menu, TRANS("Hide Others"), @selector (hideOtherApplications:), nsStringLiteral ("h"))
            setKeyEquivalentModifierMask: NSEventModifierFlagCommand | NSEventModifierFlagOption];

        createMenuItem (menu, TRANS("Show All"), @selector (unhideAllApplications:), nsEmptyString());

        [menu addItem: [NSMenuItem separatorItem]];

        createMenuItem (menu, TRANS("Quit") + String (" ") + appName, @selector (terminate:), nsStringLiteral ("q"));
    }

```

---

<div class="post-metadata">

**Author:** ![asimilon](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/asimilon/32/4235_2.png) [@asimilon](https://forum.juce.com/u/asimilon)\
**Post date:** [September 26, 2022, 5:11pm UTC](https://forum.juce.com/t/is-there-no-way-to-disable-the-macos-quit-command/53143/11 "2022-09-26T17:11:09Z")

</div>

I think it’s Objective-C, I’m also clueless about it… 😂

Just a guess, but I think this might be a good place to stick a breakpoint and see if the Quit menu option can be determined there:

```auto
        static BOOL validateMenuItem (id, SEL, NSMenuItem* item)
        {
            if (auto* juceItem = getPopupMenuItem (item))
                return juceItem->isEnabled;

            return YES;
        }

```

Looks to me that what that does is if the item in question is coming from JUCE then it returns the enabled state, otherwise it’s returning `YES` (true?). Or instead of adding a breakpoint there you could have it return false (`NO`?) and see if that perma-disables the Quit option, at least that will show it’s kind of the right place to be looking?

---

<div class="post-metadata">

**Author:** ![stephenk](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/stephenk/32/15198_2.png) [@stephenk](https://forum.juce.com/u/stephenk)\
**Post date:** [September 26, 2022, 5:30pm UTC](https://forum.juce.com/t/is-there-no-way-to-disable-the-macos-quit-command/53143/12 "2022-09-26T17:30:22Z")

</div>

Nice idea, but I put a `return NO;` at the top of that, and it disables every single item on every single popup EXCEPT the items on the Apple Menu (including Quit) that are not part of the PopupMenu additional items you pass in. 😆

So apparently this only is used for items that have a direct correspondence with items in a JUCE PopupMenu somewhere.

---

<div class="post-metadata">

**Author:** ![kerfuffle](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/kerfuffle/32/11805_2.png) [@kerfuffle](https://forum.juce.com/u/kerfuffle)\
**Post date:** [September 26, 2022, 7:33pm UTC](https://forum.juce.com/t/is-there-no-way-to-disable-the-macos-quit-command/53143/13 "2022-09-26T19:33:45Z")

</div>

It’s worse than Objective-C, it’s Objective-C++ 😅

The `createMenuItem` function creates an `NSMenuItem` object. If you capture that in a variable somewhere, then you can do `myMenuItem.enabled = NO;` to disable it (assuming the NSMenu it sits in has its `autoenablesItems` property set to NO).

---

<div class="post-metadata">

**Author:** ![stephenk](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/stephenk/32/15198_2.png) [@stephenk](https://forum.juce.com/u/stephenk)\
**Post date:** [September 26, 2022, 10:20pm UTC](https://forum.juce.com/t/is-there-no-way-to-disable-the-macos-quit-command/53143/14 "2022-09-26T22:20:30Z")

</div>

Thanks, I figured that out a little bit ago. 🙂

Actually, `createMenuItem()` already returns a pointer to the NSMenuItem. So I’m doing this at the end of `createStandardAppMenu()`, where the Quit command is added:

```auto
        // old:
        // createMenuItem (menu, TRANS("Quit") + String (" ") + appName, @selector (terminate:), nsStringLiteral ("q"));

        // fix/hack:
        [menu setAutoenablesItems: false];
        NSMenuItem* item = createMenuItem (menu, TRANS("Quit") + String (" ") + appName, @selector (terminate:), nsStringLiteral ("q"));

        if (auto* app = JUCEApplication::getInstance())
            [item setEnabled: app->getEnableQuitCommand()];
        

```

Then, in the JuceApplication.h class, add these:

```auto
public:
    void setEnableQuitCommand(bool state) { enableQuitCommand = state; }
    bool getEnableQuitCommand() { return enableQuitCommand; }
private:
    bool enableQuitCommand = true;

```

Then, when you put up a modal or whatever, you can:

```auto
app->setEnableQuitCommand(false);
rebuildAppleMenu(); // a function you should already have implemented

```

…and it works! So far - still testing and cleaning up.

Hot damn! I wrote some Objective-C++! 🤩
