Browse the docs

Answer a dialog

Waits for a sheet, dialog or file panel, fills it in by the labels beside its fields, and presses a named button.

Answer the title dialog and press press

Keyboard Maestro: Pause 0.5 then Tab Tab Return, Click in Window

Details #

"Pause 0.5, type the file name, press Tab three times, press Return" breaks the day the sheet is slow or gets a new field. This step waits for the sheet, then finds each field, pop-up and checkbox by the label a person reads beside it, sets it, and presses the button by its name. Nothing is a fixed pause, and when it can't find something it says what the dialog does have.

It looks for the dialog in the app you name (the front app when you don't): a sheet over the front window first, then a dialog window, then a floating panel with buttons. If none is open, it waits up to within seconds (10 by default), waking as soon as the app opens one. title picks one when two are open: it matches the window's title or the first line of the dialog's text.

You writeThe step does
fields: {"Save As": "report"}Replaces the contents of the field labelled Save As
choose: {"Format": "PDF"}Opens the Format pop-up and picks PDF (or picks it in a radio group or segmented control)
check: {"Open in Preview": true}Ticks or clears the checkbox, only when it differs
folder: "~/Desktop"In a file panel: ⌘⇧G, types the folder into "Go to the folder", and presses Go
press: ["Save", "Replace"]Presses Save; waits for the next dialog; presses Replace

Fields are filled first, then pop-ups, then checkboxes, then the folder, then the buttons. A label that isn't there yet (a Format change can add fields) is tried again after the others. Each setting is read back, so the step reports what each control was and is now.

A label is matched like a menu item: exact, then starting with it, then containing it, ignoring case, accents and a trailing colon. It is looked for in this order: the control's own title, the label it points to, its description, its placeholder, then the nearest text to its left on the same row or directly above it. A label must name a field for fields, a pop-up or radio group for choose, and a checkbox for check. When two controls match equally, the step fails and gives both positions, never a guess.

When a later button in press has no dialog to press in (the file didn't exist, so there is no Replace sheet), the step waits 2 seconds and then skips the rest, saying so. A button that is greyed out is waited for, then reported.

The step reports {title, text, fields, buttons, pressed} as the dialog was when it was found, plus set (every control's label, was, now) and closed (whether the dialog went away). into receives that object.

Parameters #

ParameterTypeRequiredValuesWhat it does
apptextThe app to look in, by bundle id. The front app when blank.
checkrecord
chooserecord
fieldsrecord, choose, check: Tables of label and value.
foldertextFor a file panel: the folder to go to. ~ is your home folder.
ifAbsentone offail skipfail (the default) or skip, for a dialog the app only sometimes shows.
intotextA variable that receives the dialog.
pressany valueA button title, or a list pressed in order.
titletextOnly a dialog whose window title or first line matches. Plain text, or /regex/.
withinnumberSeconds to wait for the dialog to appear. Default 10.

Every step also accepts label, onFailure, timeout and dryRunSafe.

Examples #

Save As in TextEdit, replacing an older file
Do
  1. Choose File › Save… in TextEdit
  2. Answer the dialog: Save As “notes”, folder ~/Desktop, press “Save” then “Replace”
Open in Switchboard to try it
Export as PDF, with the Format pop-up
Do
  1. Answer the “Export” dialog: Save As “invoice”, Format PDF, Open in Preview on and 1 more
Open in Switchboard to try it
Answer "Are you sure?" when it appears
Do
  1. Answer the dialog: press “Delete”
Open in Switchboard to try it
Press Replace when Xcode asks
When
  1. An error dialog appears in Xcode saying “replace” with the “Replace” button
Do
  1. Answer the dialog: press “Replace”
Open in Switchboard to try it

Gotchas #

  • Permission and password prompts (owned by the system's security agent) are refused on purpose. You answer those.

  • A dialog that a game or Java app draws itself has no tree to read; use Click with a position.

  • Web dialogs are divs: they work only when the page describes them to Accessibility.

  • The step doesn't confirm the folder a file panel ends up in, only that the Go to the folder box closed. Check the Save As field's path in a test run.

  • A dry run reads the open dialog and reports what it would set and press; it changes nothing.

See also #

Set a control, Press button by name, An error dialog appears, Wait