Is it Possible to Select a Menu Item Using a Name Containing Variables Set by a User?

Works perfectly! Thank you so much!

Working version for future searchers:

10%20AM

Thanks for sharing. Would you mind also uploading the macro file?

1 Like

Absolutely!

SEARCH AND FOCUS WINDOW - SEARCH FOR OPEN BIN 3.0 MENU VERSION.kmmacros (7.0 KB)

Macro-Image

image

However, I'm in the process of improving it. I've widened the scope to include all menus in the application via AppleScript. It creates a list of every menu item in the application as desired but I don't know how to tell it which menu to find the user-selected item is in.

Is there any way to Select Menu > Menu Title = "Any" > Menu Item %userSelectedWindow%?

I have accomplished searching all menus using apple script. Once I've figured out how to incorporate sub-menus I will post.

Did you ever manage it? There have been a few requests about this kind of thing lately.

Like what?

My memory isn't bad, but June is pushing it.

1 Like

Getting every menu item and every submenu item in an app via AppleScript tends to be pretty slow.

Using Google Chrome as my test app and running from Script Debugger 8.0.5 (8A61) on OSX 10.14.6.

tell application "System Events"
   tell application process "Google Chrome"
      tell menu bar 1
         set menuRefList to entire contents
         set menuRefListLength to length of menuRefList
      end tell
   end tell
end tell

On my old i7 MacBook Air it takes around 22 seconds to return a list of 9849 values.

Let's try a more modest app like TextEdit...

551 items in about 1.4 seconds.

Not bad, but then again those are pure AppleScript references and are not very useful without further processing.

More and more time gets added in.

Entire contents tends to be slow anyway, and one might actually get better speed by building a recursive routine to go through every menu and submenu.

The moral of this story is that I would never try to grab every menu item and submenu item from an app without a very good reason.

Might the solution be to perform the search when the app launches, and then reference the result later when trying to access menu items? As I type this, I'm fairly sure I saw someone do this to good effect. Posssssibly with Pro Tools. So much for my "good" memory.

That wouldn't be a bad solution if you didn't have to get changing values from dynamic menus.

Another possibility would be to run the menu-scraper routine manually at need.

1 Like

Then you have the added complication that some apps (I'm looking at you, Logic Pro!) don't refresh their menu item status until the menubar is clicked. When I need to test (and click, in this case) the status of a menu item in Logic, my workaround is:

You can also do that with AppleScript, so when you know a menu will be populated that way you can build it into the scraping script.

1 Like

Erm... Wasn't it us?

1 Like

Jeez. I'll be finding my phone in the fridge next.

1 Like