Disable item in Mac menu

Is there a way to do this from Juce? I can add menu items to the Mac app menu with SetMacMainMenu(), but I could not see a way to disable or enable those items from Juce? I can dig into the Mac API and do it directly, but thought I’d post this question first in case I missed a way to do it from Juce.

Am not sure about it working on macintosh, but I had used ApplicationCommandTarget for enabling and disabling the menu items on wndows.

You would have to derive a class from ApplicationCommandTarget and over-ride this method.

virtual void ApplicationCommandTarget::getCommandInfo ( const CommandID commandID, ApplicationCommandInfo & result ) ;
result.setActive ( false) ; // disables
result.setActive ( true) ; //enable


If that doesn’t work you can use any of these methods to get the menu item

– itemWithTag:
– itemWithTitle:
– itemAtIndex:

and call setEnabled to enable or disable the menu item

example :

NSMenuItem* Item = [menu itemAtIndex:0];
[Item setEnabled:false]; 

It’s no different to disabling items in the non-native menus.

vishvesh is right about command manager stuff, and the normal Menu::addItem method has an enable parameter too.

I have not tried vishvesh suggestions yet, but setting the enable parameter false in the addItem() method did not seem to work. It is not a big deal, because I really need a way to be able to disable and enable after the item is added and it looks like it won’t be hard following vishvesh’s suggestions.

sorry to exhume this old thread but I have exactly the same problem.
I tried both the addItem and addCommandItem methods and it does not disable the item in Mac. I went into the code and the disabled flag in NSMenuItem seems to be correctly set.
But when I click on the menu, the item is enabled.
Does anyone achieve to disable menu item in Mac Main menu?

That sounds very odd! The disable flag certainly works for normal menus… Maybe the OS treats the main one as a special case and simply doesn’t support disabled items…?

Yes, it seems that Mac OS doesn’t allow us to disable an item. But it supports disabled items because the Mac OS “Show All” item is disabled by default.
There must be a trick.
BTW the ticked flag works.