Browse the docs

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 #

ParameterTypeRequiredValuesWhat it does
expectany value"output:<regex>" or {"output": "<regex>"}.
jstextJavaScript; its returned value decides.
sampleyes / noThe answer used in a dry run.
shelltextCommand text. {{ }} expressions are filled in first, so quote anything that could contain spaces.

Examples #

Only when Git has changes
When
  1. Press ⌃⌥J
Only if
  1. If the script “git -C ~/Code/app status…” returns “output:.”
Do
  1. Show “Uncommitted changes”
Open in Switchboard to try it
Only when a host answers
When
  1. Press ⌃⌥J
Only if
  1. If the script “ping -c1 -t1 192.168.1.1” returns success
Do
  1. Show “Router is up”
Open in Switchboard to try it

Gotchas #

See also #