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 write | The 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 #
| Parameter | Type | Required | Values | What it does |
|---|---|---|---|---|
app | text | The app to look in, by bundle id. The front app when blank. | ||
check | record | |||
choose | record | |||
fields | record | , choose, check: Tables of label and value. | ||
folder | text | For a file panel: the folder to go to. ~ is your home folder. | ||
ifAbsent | one of | fail skip | fail (the default) or skip, for a dialog the app only sometimes shows. | |
into | text | A variable that receives the dialog. | ||
press | any value | A button title, or a list pressed in order. | ||
title | text | Only a dialog whose window title or first line matches. Plain text, or /regex/. | ||
within | number | Seconds to wait for the dialog to appear. Default 10. |
Every step also accepts label, onFailure, timeout and dryRunSafe.
Examples #
- Choose File › Save… in TextEdit
- Answer the dialog: Save As “notes”, folder ~/Desktop, press “Save” then “Replace”
- Answer the “Export” dialog: Save As “invoice”, Format PDF, Open in Preview on and 1 more
- Answer the dialog: press “Delete”
- An error dialog appears in Xcode saying “replace” with the “Replace” button
- Answer the dialog: press “Replace”
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