Ask for input
Asks you for text, a choice from a list, or several fields in a form, and stores the answer.
Ask text
Keyboard Maestro: PromptForUserInput, PromptWithList, Alert
Details #
Opens a keyboard-first panel and waits. It takes the keyboard when it appears and gives it back to the app you were in when it closes. kind picks the shape:
text: one text field. The answer is a string.secure: truehides what is typed.list: pick one item fromitems. Typing filters the list (every word must match), ↑ and ↓ move, Return picks, double-click picks. The answer is the chosen string.form: several namedfields, plus buttons fromitems. The answer is an object with one key per field.pickRegion: no window; the screen dims and the pointer becomes a crosshair. Drag a box over what you want (a live size shows beside it), hold Space while dragging to move the box, click without dragging (or press Return) to pick the window under the pointer, ⎋ to cancel the run. The answer is a record{x, y, w, h, display, option, shift, window}in screen points from the top left, which Read text on screen takes as itsregion.optionandshiftsay whether ⌥ or ⇧ was held when you let go.messageis the one-line hint at the top of the screen.mode: pointtakes a click instead of a box.
Return presses the default (first) button, Escape cancels, and ⌘1 to ⌘9 press the first nine buttons.
The answer is the step's output. If into is set, it also goes into that variable. For a form, every field also becomes a variable of its own name, so {{email}} works right away. promptButton holds the title of the button pressed, whichever one it was.
A form field's type picks its control: text (the default), multiline (Return adds a line, ⌘Return answers), secure, menu (choose from its options), checkbox (the value is true or false), file or folder (a Choose button opens the file panel; the value is the path).
Parameters #
| Parameter | Type | Required | Values | What it does |
|---|---|---|---|---|
kind | one of | Yes | text list form custom panel pickRegion | text, list, form, panel or pickRegion. panel is the Show a panel step spelled as a prompt, for extensions and old macros. custom is in the list but fails and points to panel. |
ai | yes / no | true adds the AI badge: a model wrote the question. | ||
body | record | |||
buttons | list of text | |||
default | text | The starting text for text, or the preselected item for list. | ||
fields | list of record | For form: a list of {"name", "label", "default", "type", "options", "placeholder"} objects. name is required and becomes the key and the variable name. label defaults to the name. type is text, multiline, secure, menu, checkbox, file or folder. A menu needs options; its default is the first option. | ||
id | text | |||
into | text | The variable that receives the answer. | ||
items | any value | The choices (for list) or the buttons (for form). Give an array, or one string with one choice per line, such as "{{lines}}". Blank lines are skipped. options is accepted as a synonym. | ||
itemsFile | text | A file with one choice per line, added to items. A leading ~ is expanded. Files over 2 MB are refused. | ||
keepOpen | yes / no | |||
message | text | The line of explanation above the field. text works as a synonym. | ||
mode | one of | region point | For pickRegion: region (drag a box, the default) or point (click). | |
options | list of text | |||
position | one of | center cursor top | ||
secure | yes / no | For text: hide what is typed. | ||
text | text | |||
title | text | The window title. Defaults to the macro's name. | ||
wait | yes / no | |||
width | number |
Every step also accepts label, onFailure, timeout and dryRunSafe.
Examples #
- Ask for text
- Show “Hello, {{name}}”
- Ask to choose from 0 options
- Ask for 2 fields
- Show “{{project}}: {{task}} by {{due}}”
- Ask for 5 fields
- Show “{{promptButton}}: {{headline}}”
Gotchas #
Every button returns its own title in
promptButton; the fields come back the same whichever button was pressed. Cancel (Escape) is the only way out that fails the step.A dry run does not open the dialog. It answers with the step's
samplewhen there is one (a macro test gives it by step id under Samples), else with the defaults: thedefaulttext, thedefaultitem (or the first item), and each field'sdefault. A form sample missing a field gets that field's default. Set sensible defaults so a dry run reaches the steps after it.Cancelling the dialog fails the step with "cancelled by you", and the macro stops. Set the step's
onFailuretocontinueorbranchif cancelling is a normal answer.A
listprompt with no items fails. Aformfield with nonamefails.With no
into, atextanswer is shown in the trace but not kept. Alistanswer is still kept inpromptWithListResult(and its position, counting from 1, inpromptWithListIndex). Forms still set one variable per field.It waits for you, so it has no 10 s default limit. The macro's own timeout (60 s unless changed) still ends it.