Choose menu item
Chooses an item from an app's menu bar by its path, such as File, Export.
Choose menu item in app
Keyboard Maestro: SelectMenuItem
Details #
Walks the app's menu bar one title at a time and presses the last item. The output holds the menu path that was chosen. It works on the front app, or on the app you name in app. The app does not need to be in front for you to choose an item from it.
path is a list of titles, such as ["File", "Export…"]. Matching ignores case and extra spaces, and ... and … count as the same. Instead of a full title, a part can be a pattern between slashes, matched without regard to case: ["File", "/^Export/"].
If an item is not there yet, or is greyed out, the step waits and tries again every 0.1 seconds, for up to the step's timeout minus a short margin (2 seconds if the step has no timeout). A menu that fills in a moment after a click is found without extra pauses.
When it fails, the Trace says which level was missing, lists the titles it did find, and suggests the closest one: There's no "Export" in the "File" menu. Did you mean "Export…"?. A greyed-out item is reported as such, with a hint that a document may need to be open or something selected.
Choosing a menu item beats a keyboard shortcut when the shortcut differs between apps, or when you do not know it.
Parameters #
| Parameter | Type | Required | Values | What it does |
|---|---|---|---|---|
path | list of text | Yes | The titles from the menu bar down, as a list. Required. | |
app | text | The app, by bundle id or name. Defaults to the front app. | ||
show | yes / no | Opens the menu so you can see it, instead of choosing the item. Off by default. |
Every step also accepts label, onFailure, timeout and dryRunSafe.
Examples #
- Choose Edit › Select All in Safari
- Choose File › /^Export/
Gotchas #
Menu titles follow the app's language. A macro written for an English app will not find "Ablage" in a German one.
Items that open a submenu are walked through, not pressed. Only the last title in the path is pressed.
Items such as Open Recent change over time. Use a pattern.
Switchboard needs the Accessibility permission to read menus.
Recorded when #
The Recorder writes this step when you choose an item from the app's menu bar, or press a shortcut that is one of its menu items (the keys stay in the step's label). The app is set, so it runs in the background. See Recording a macro.