Variable
Passes when a variable compares true against a value.
name op value
Keyboard Maestro: Variable, Text, Calculation
Details #
Reads the variable name from the run and compares it with value using op. name is the variable's name, not text to fill in; value may use {{ }} expressions. A variable that was never set is nothing, and counts as empty.
Operators: == or eq, != or ne, < or lt, <= or lte, > or gt, >= or gte, contains, startsWith, endsWith, matches, isEmpty, before and after (alphabetical order of the two texts).
Equality is loose: the number 5 equals the text
"5". Two texts must be identical.Ordering compares numbers (or text that reads as a number) as numbers and other text as text. Comparing things that can't be ordered, such as a list and a number, is an error.
containslooks for an item in a list, a key in a record, or a piece of text in text.matchessearches for a regular expression, case sensitive.isEmptyis true for nothing, empty text, an empty list or an empty record. It ignoresvalue.
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 the variable's value under its own name, plus op and value.
Parameters #
| Parameter | Type | Required | Values | What it does |
|---|---|---|---|---|
name | text | Yes | The variable to read. | |
op | one of | Yes | eq ne gt lt == != < <= > >= contains matches isEmpty gte lte startsWith endsWith after before | One of the operators above. |
value | any value | What to compare with. Omit for isEmpty. |
Examples #
- Set count to “3”
- If count is at least “3”
- Show “Three or more”
- Else
- Show “Fewer than three”
Gotchas #
An
onlyIflist is checked before the first step, so a variable set insidedoisn't visible to it. Use anifstep to test a variable you set during the run, as the example does.When a trigger is being considered, the check runs before any run exists. Variables are empty then, so a
variablecondition belongs in anifstep in most macros.