Browse the docs

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 #

ParameterTypeRequiredValuesWhat it does
pathlist of textYesThe titles from the menu bar down, as a list. Required.
apptextThe app, by bundle id or name. Defaults to the front app.
showyes / noOpens 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 (really presses a menu item)
Do
  1. Choose Edit › Select All in Safari
Open in Switchboard to try it
Choose any Export item in the File menu (really presses a menu item)
Do
  1. Choose File › /^Export/
Open in Switchboard to try it

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.

See also #

Press keys, Click, Activate app