Not a real bug, but maybe worth mentioning

Hi Carlo,
My first test of the UI actions was of course directly in the Shortcuts application. I used the action “In Shortcuts, select the menu whose title is darkmode” to call the menu item/shortcut “darkmode” that was under “Open Recent”. Interestingly, I noticed that this shortcut is executed directly, so my screen goes dark in this case. I looked into this and found out that all items in the “Open Recent” menu are executed when the “Service Menu” shortcut option is selected. Otherwise, the shortcuts only open in Editor mode.

– Leif

Interesting find but not all that surprising (to me, knowing the code). What “Select menu item” does is triggering the first menu item that fits the bill. Since the workflow has “Services Menu” enabled, it will show up in both menus, and the Services menu comes before the Recent menu (the search starts on the top left menu)…

UIA clearly still lacks the docs, but I want to nail down the basics first before explaining everything. And watching you friendly beta testers find weird/unexplained stuff helps me straightening out the wrinkles. :wink:

I think you can use paths or segmented paths for Select Menu Item so that should allow you to select a specific menu item. It’s only a problem when just specifying just the title since UI Actions always selects the first one it finds.

Of course, that might be good or bad since the first two menus in the app menu bar are Apple and app (e.g., Shortcuts). In this case, I created a DarkMode shortcut that uses Turn appearance Dark, Wait 5 seconds, Turn appearance Light; I also selected Services Menu under Use as Quick Actions on the Shortcut Details tab, which adds this shortcut to the system Services menu. So then when I use UI Actions to Select Menu Item whose title is DarkMode, it finds it in the Services menu and it runs.

I don’t think it’s a good idea to use the Open Recent menu to select a menu item because that would be dynamic, and you can’t depend on what it might contain based on recent activity. Actually, in my case, even though I ran DarkMode, I do not see it showing up under Open Recent, which shows 10 other shortcuts that I have run.

If you want to run a shortcut, just use the Shortcuts action “Run Shortcut”; you don’t need UI Actions, which wouldn’t be as direct. Remember you mix and match actions from any app in your Shortcuts, with UI Actions only be one of them. Use it for its unique capabilities when you don’t have other actions already provided by those apps.

1 Like

Thanks @czottmann and @doug78645 for your explanations, I now understand that the UI action will traverse the entire menu tree and process the first item it finds. Regardless if this is part of the MacOS or the application, so it is also possible to call Apple menu items, e.g. “About this Mac” from any application. That is fine for me, never the less, using the name of a menu item instead of a complex menu path is very convenient.

You’re right, it’s not a good idea to use dynamically filled menus for a shortcut. I didn’t do so, for the reason of building a real workflow, it was just a quick and dirty test case :wink:

1 Like