Script
Passes when a shell command succeeds or JavaScript returns a truthy value.
shell succeeds
Keyboard Maestro: Script (Succeeds, Fails, Is, Contains, Matches)
Details #
Runs the code for real and checks the result. A shell command runs under /bin/zsh -c and passes when it exits 0. A js snippet runs with the run's variables in vars and passes when it returns a truthy value. Give one of them.
expect checks the output instead. Write "output:<regex>" or {"output":"<regex>"}: the condition passes when the output matches the regular expression, whatever the exit code. Without expect, the exit code (or a truthy JavaScript result) decides.
Both kinds stop after 5 seconds. Keep checks quick.
Every condition accepts "negate": true, which flips the verdict. The trace records what was compared before the flip, so a negated condition that blocks a macro still shows the real values.
Conditions in an Only if list combine with all: every one must pass, and an empty list always passes. An if step or a repeat loop takes a match of all (default) or any.
The trace shows exit (the exit code) and output (the first 200 characters).
In a dry run the script does not execute. The condition answers with sample, which defaults to true, and the trace shows simulated.
Parameters #
| Parameter | Type | Required | Values | What it does |
|---|---|---|---|---|
expect | any value | "output:<regex>" or {"output": "<regex>"}. | ||
js | text | JavaScript; its returned value decides. | ||
sample | yes / no | The answer used in a dry run. | ||
shell | text | Command text. {{ }} expressions are filled in first, so quote anything that could contain spaces. |
Examples #
- Press ⌃⌥J
- If the script “git -C ~/Code/app status…” returns “output:.”
- Show “Uncommitted changes”
- Press ⌃⌥J
- If the script “ping -c1 -t1 192.168.1.1” returns success
- Show “Router is up”