Menu Items Disabled in MACos Menubar App

menu items disabled in macOS menubar App

Your Quit menu item is working "accidentally". It is not using the terminate(_:) method you implemented. Put a print() statement there and you'll see it's not being invoked.

A menu item either has a specific target object assigned or it uses the responder chain to search for an appropriate target. You are not assigning a target for your menu items, so they are using the responder chain. Your MenuBarActions class is not part of the responder chain. (Classes generally can't be. Certain objects can be.) So, the menu items will never target your class.

The Quit menu works because the application object is on the responder chain and it has a terminate(_:) method. In fact, that's what your terminate(_:) method would invoke if it were ever being called. But the menu item is actually invoking it directly.

You should create an actual controller object (not just class) that implements the action methods and set the menu items' target property to it.

StatusItem in MacOS menubar is greyed out and doesn't work

You have to set the target.

let playMenuItem = menu.addItem(withTitle: "Play Pause", action: #selector(onClickPlayPause), keyEquivalent: "1")
playMenuItem.target = self

The Quit item works via First Responder.

Menu in system status bar is disabled

Menu validation does not find any implementor of specified action in responder chain so disable it. You have to specify target for each menu item:

    let item = menu.addItem(
withTitle: "Order a burrito",
action: #selector(StatusBarFactory.x(_:)),
keyEquivalent: "A")
item.target = _instance_of_StatusBarFactory_here // like StatusBarFactory.shared

Is there anyway to hide menubar items in MacOS?

As for application menus on the left, those can't be hidden, I'm pretty sure.

Applications often have the option to enable or disable their menu bar helper app in the main preferences. If that doesn't help, e.g. if it's a full-fledged menu bar app, not just a helper, then to my knowledge the only solutions are Hidden Bar, which you mentioned, and Bartender.

I'm using the latter, and it does a very fine job. You have four options in Bartender's preferences:

  1. Show (default macOS behavior)
  2. Hide (menulet will be hidden in a special Bartender secondary menu bar, accessible via the triple-bullet icon ··· on the far right)
  3. Always show (menulet will be visible in the main macOS menu bar as well as the secondary Bartender menu bar at the same screen position)
  4. Always hide (menulet will be completely hidden)

Some older menulets seem to switch their position occasionally, e.g. after wake-from-sleep, and Bartender isn't yet able to fix the position of BitBar instances. But for the vast majority of menu bar apps and helpers it will work just fine.

Disabled wxWidgets menu on MacOS

MaxOS bundle should be set in CMakeLists.txt script:

if(APPLE)
set_target_properties(app-target PROPERTIES
MACOSX_BUNDLE TRUE
XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "" # to disable code sign
)
endif()

Now MacOS application will be created (.app) instead of just an executable.

This also solves problem with appearing console when launching from Finder.

How can I use AppleScript to find disabled menu items?

In order to get the properties of a menu item, you first need to get a reference to that menu item. You would then need to go through the various menu items and build lists or records of those that meet your criteria, so that the references can be used as needed.

From the comments, general-purpose handlers to click at or get menu references by using a list of the menu hierarchy would serve your purpose, so those would be something like:

on run -- examples
#clickMenu at {"Finder", "View", 10, "Name"} -- note that there are 2 "Clean Up" items
set menuRef to getMenuReference for {"Script Editor", "File", "New"}
log result
clickMenu at menuRef -- clickMenu at {"Script Editor", "File", "New"} can also be used
end run

to getMenuReference for menuList -- Get a reference to a menu item in an application's main menu.
(*
The menu hierarchy is described in the menuList parameter.
The last menu item doesn't need to be exact, just close enough for a match.
Menu items can also be integer indexes (separators are counted).
When using an index, note that menus can contain dynamic or hidden items.
parameters: menuList [list] -
item 1 [text]: the application name
item 2 [text]: the menu bar item name
item(s) 3+ [text or integer]: the (sub)menu item(s)
returns the reference or missing value
*)
try
set itemCount to (count menuList) -- needs to be at least {application, menu, item}
if itemCount < 3 then error "menuReference handler: the menu item list contains too few items"
set {appName, menuName} to items 1 thru 2 of menuList
set {menuItem, found} to {last item of menuList, false}
tell application appName to activate
tell application "System Events" -- set up the menu path
set appName to (name of application processes whose frontmost is true) as text -- handle different process names
set menuPath to menu menuName of menu bar item menuName of menu bar 1 of application process appName
if itemCount > 3 then repeat with i from 3 to (itemCount - 1) -- add sub menu items
set menuName to item i of menuList
if class of menuName is integer then set menuName to item menuName of (get name of menu items of menuPath)
set menuPath to menu (menuName as text) of menu item (menuName as text) of menuPath
end repeat
if class of menuItem is not integer then -- the target menu item
repeat with anItem in (get name of menu items of menuPath)
if anItem begins with (menuItem as text) then -- match a partial string (also 'contains', etc)
set {menuItem, found} to {anItem, true}
exit repeat
end if
end repeat
if not found then error "menuReference handler: menu item " & quoted form of menuItem & " not found"
end if
return menu item menuItem of menuPath
end tell
on error errorMessage number errorNumber
log errorMessage
# error errorMessage number errorNumber -- uncomment to pass error up the chain
end try
return missing value
end getMenuReference

to clickMenu at menuItem -- Click a menu item in an application's main menu.
(*
The menuItem can be a reference to the menu item or a list of the menu hierarchy.
parameters: menuItem [reference or list] - see the getMenuReference handler
returns true if successful, false otherwise
*)
try
if class of menuItem is list then -- get a reference
set menuItem to getMenuReference for menuItem
if menuItem is missing value then error "clickMenu handler: the menu item was not found"
end if
tell application "System Events"
# log (get properties of menuItem)
if (enabled of menuItem) then -- filter for desired property
click menuItem
delay 0.25
return true -- success
end if
end tell
on error errorMessage number errorNumber
log errorMessage
# error errorMessage number errorNumber -- uncomment to pass error up the chain
end try
return false -- failure
end clickMenu

Menu bar menu entries get disabled after period of time

I am the author of a similar app, that sits in the menu bar and I've been able to keep it running for long stretches without ever seeing the issue you are describing. While I don't know exactly what is causing your problem I can say that I use a strong IBOutlet reference for my NSMenu which seems to work just fine.

How to disable Mac's About/Quit menu items when showing a JDialog?

By default, the application menu entries do nothing when a modal dialog has focus, but the appearance is unaffected; this is standard on Mac OS X interface. Of course, your application's own menus should be enabled or disabled as appropriate. You can intercept the relevant events using OSXAdapter, as shown in this answer.

disable menu bar and dock programmatically in mac

This article contains some good info and links on creating a full-screen app that hides the Dock and menubar.



Related Topics



Leave a reply



Submit