Skip to main content

Conditions

A condition lets an action decide. An If block runs the steps inside it only when its condition is true; an If… otherwise… block runs one set of steps or the other.

Adding an If block​

  1. Select the step the block should follow (or no step, to add it at the end).
  2. Click If / loop and choose If… or If… otherwise….

If… adds two rows, If and End if. If… otherwise… adds If, Otherwise and End if. The If row is selected, so the next step you add goes inside the block. Steps between If and Otherwise run when the condition is true; steps between Otherwise and End if run when it is false. Then the action continues after End if.

1IfWindowContainsTitle(ContextGetWindow(), Notepad)
2Send keys^S
3Otherwise
4Show a notificationNot Notepad, Nothing was saved.
5End if

Blocks can sit inside other blocks. There is no "otherwise if": put another If block inside the Otherwise part.

The condition​

Select the If row to edit its condition. Check chooses one of three kinds:

If
Check
Compare two values
Reverse the result (not)
Value
$answer
Comparison
is equal to (==)
Compared with
Yes

The fields you fill in for one kind are kept while you try another, but only the chosen kind ① is saved.

Compare two values​

Value, Comparison and Compared with. Each value is typed, a $variable, or a reading chosen from the field's value menu, such as Clipboard text or Target window (Choosing a value from the menu). Both fields offer every reading. Typing a reading's script name with empty parentheses, such as ClipboardGetText(), is the same as choosing it. The comparisons are is equal to (==), is not equal to (!=), is less than (<), is at most (<=), is greater than (>) and is at least (>=).

How a typed value is read: a number (such as 3 or 2.5) is a number, true or false is true or false, a named constant (such as MouseButton.Right) is its number, and anything else is text. So you can't compare against the text "3"; compare against a variable that holds it.

The rules:

  • Two texts are equal only if they match exactly, including upper and lower case.
  • Two numbers are compared by value, whole or not: 5 equals 5.0.
  • Two windows are equal when they are the same window.
  • Values of different types are never equal: the text "5" isn't equal to the number 5.
  • is less than and the other orderings work on two numbers, or on two texts (in character-code order, so "Z" comes before "a"). Any other pair is false for all four.

These are the script language's rules; see Mixed-type rules.

A builtin's result​

The condition runs a builtin and uses what it gives. Choose a builtin… opens the list of all builtins (Adding and arranging steps); pick one and click Use this builtin. Its fields then appear below, as for any step. Until a builtin is chosen, the field says Choose the builtin whose result is checked.

Builtins made for this usually have Is or Contains in their name, such as Is window maximized (WindowIsMaximized) or Title contains text (WindowContainsTitle), and give true or false. Any other result counts as true or false by the rules below.

A field of the condition's builtin can hold a builtin call only through a variable, as for any step; Move into a variable adds the step above the If (Step parameters).

A value or variable​

Value holds one value, usually a $variable, or a reading from its value menu, as above. The condition is true when the value counts as true:

TypeCounts as true when
True or falseit is true
Whole number, Numberit isn't 0
Textit isn't empty
Windowit is a window (a step that found nothing gives no window)

This is how you check "did the step find something": save the step's result, then test the variable. See Value types.

Reverse the result​

Reverse the result (not) ② turns true into false and false into true. Use it for "if the window is not maximized" with A builtin's result and Is window maximized.

Stopping early​

Stop the steps, from the If / loop menu, ends the action at that point; the steps after it don't run. Put it inside an If block to stop only in some cases.

Jumping to a step​

The steps' text form also has a "go to step" form of if, which jumps to another step by its number. The step list can't show it. An action that uses it can only be edited as text, in the code view (From Steps to Script), and the editor says so (Problems). Use blocks instead whenever you can.