Check menubar item disabled status then if/else condition

Is there a way to check the status of a menubar item whether it's enabled or disabled? ChatGPT only gave me a script that returns true or false in the script result but I don't know how or where to save the returned value and use that for If condition action.

Here's the script:

tell application "System Events"
    tell process "Figma"
        set menuItemEnabled to (enabled of menu item "Go to Main Component" of menu "Main Component" of menu item "Main Component" of menu "Object" of menu bar 1)
    end tell
end tell
return menuItemEnabled

Thank you.

@Andreas_Hegenberg Hi, is there a better way to do this? I'm not sure I explained it very well. Determine if menubar item is disabled, then do this action. Otherwise, do this action. Stuff like that.

For example, in Figma, if I press a custom trigger — Opt+C and this menu item is disabled →

...BTT will detect this "Return to instance" button and click it :thinking:

I think this could save me from having to assign two shortcuts to each of them.

You can do it like this:

async function someJavaScriptFunction() {

    let menuItemDetailsString =   await get_menu_item_details("Edit;Cut");
    let menuItemDetails = JSON.parse(menuItemDetailsString);
     return menuItemDetails.enabled;
}

This would check the enabled state of the Edit => Cut item. You can also get the "checked" state via .checked

1 Like

Oh my god it works! I was gonna ask why when doing the script test run it always returns false but I don't think that matters. Thank you :slight_smile:

if you click the run button while BTT is frontmost, it will try to get the details from BTT‘s menubar. You can click the „run script“ button while pressing cmd, then BTT will stay in background

1 Like

Hi! I'm not sure why but these past few days, the script doesn't always 100% work or unreliable when triggered. If I manually click the "Run script" button here, it would work as expected. But then after a few minutes, it's back to the issue.

Also, unrelated but if I check the "Run in background (limited support)" option, it turns off when I navigate away :thinking:

I have BTT v4.769 and the process priority helper tool installed.
I also have the Ice menubar app installed, maybe BTT is conflicting with it?

JS is always run in background, I should hide that checkbox here.

Was there maybe an update to the app where you are checking the menubar?

Got it. Yes (probably). The menubar items' name are the same as before :thinking:

Which app is this? Maybe I can have a look

Figma. Thanks a lot :slight_smile:

ah electron apps have been a bit picky with this menubar stuff since macOS 14

For some users calling the function twice has worked (the first one would kind of wake up the process). Something like this

async function someJavaScriptFunction() {

    // dummy call to wake up the menu
    await get_menu_item_details("Object;Main Component");

    let menuItemDetailsString = await get_menu_item_details("Object;Main Component;Go to Main Component");

    let menuItemDetails = JSON. parse(menuItemDetailsString);
    return menuItemDetails.enabled;
}
1 Like

I see! I think this is what I've been meaning to ask, something to "wake it up". I will test but I think this is the best solution. I really appreciate you looking into it :v:

Hi @Andreas_Hegenberg

Just to follow up, I've noticed that key sequences triggers work 100% most of the time but it's the keyboard shortcut and swipe gestures that don't. Why is that? :thinking:

I can't think of a reason. Are you maybe using them with modifier keys that would change the state of the menu?

I even just have a single action "Trigger Menu Bar Menu-Item" (plus the esc action)

Opt+C for keyboard shortcut

And, M-C (key down only) for key sequences with delay


For the keyboard shortcut to work, I have to open the BTT main window, even though I have it pinned in my menubar. But the key sequence just works :thinking:

Could you check if that menu item in Figma works when you click it while holding option key?

Yes it does

Weird, unfortunately then I have no idea. Some items change their name when option is pressed, which might explain the shortcut issue, but apart from that I can't think of anything.

Interesting. Thanks anyway!