If
Runs one list of steps when its conditions pass and another when they don't.
If conditions
Keyboard Maestro: IfThenElse
Details #
Checks the conditions. If they pass, the steps in then run. If not, the steps in else run, when there are any. The Trace shows which branch ran, and what each condition compared.
By default every condition must pass (match: all). Set match to any to pass when one is enough. An empty list of conditions always passes.
Any condition type works here, the same ones as in Only if. Conditions can use {{ }} in their values.
- Set count to 3
- If count is above 2
- Show “Plenty”
- Else
- Show “Not enough”
Parameters #
| Parameter | Type | Required | Values | What it does |
|---|---|---|---|---|
conditions | list of condition | Yes | A list of conditions. Required. Each may be negated. | |
then | list of steps | Yes | Steps to run when the conditions pass. Required. | |
else | list of steps | Steps to run when they don't. Optional. | ||
match | one of | all any | all (default) or any. |
Every step also accepts label, onFailure, timeout and dryRunSafe.
Examples #
- If a file exists at ~/Desktop/a.txt and a file exists at ~/Desktop/b.txt
- Show “Found one”
Gotchas #
A step inside then or else that fails stops the macro, unless that step handles its own failure. If it still fails, this step's own onFailure applies.
A condition that can't be checked (a bad regular expression, comparing a list with
<) fails the step. It does not count as false.Return a value, Stop macro, Break out of repeat and Next repeat inside a branch act on the whole macro or the surrounding loop.