I’m trying to use a regular expression with the Select Menu By Name action, but it doesn’t seem to work as expected. Instead of behaving like a regex match, it seems to be performing a basic string search.
Here’s what I’m aiming to achieve:
• Goal: Display all my favorited actions except for those with “help” in the name.
• Test Case: As a simple test, I wanted to use a regex pattern to display all names under the “Edit” menu. Based on what I’ve read (link), I expected ^Edit.* to work, but instead, I’m getting “No Results.”
Has anyone encountered this issue before? Is there something I’m doing wrong? Are there any known workarounds or additional steps needed to make regex work properly with this action?
Yes, I have found this to be the case. I would guess that the underlying design of Select or Show a Menu Item is probably quite different, with Select Menu by Name having more code in common with Trigger Macro by Name.
While some text fields allow regex matching, the one in "Select Menu by Name" is an (implicit) "contains".
However, because your actual goal is well defined there's a workaround. Use an "Execute an AppleScript" action to get a list the items in the "Favorites" menu that don't have "help" in their name, use that list in a "Prompt with List" action, use the result of that in a "Select or Show a Menu Item" action.
Here's the AppleScript, long-form so you can see how to work through the menu structure -- give the rest a try and see how you get on:
tell application "System Events"
tell process "Keyboard Maestro"
tell menu bar 1
tell menu "edit"
tell menu item "Insert Action"
tell menu "Insert Action"
tell menu item "Favorites"
tell menu "Favorites"
set theList to (get name of (every menu item whose name does not contain "help"))
end tell
end tell
end tell
end tell
end tell
end tell
end tell
end tell
set AppleScript's text item delimiters to linefeed
return theList as text