Conditional Branches
Conditional Branches
Section titled “Conditional Branches”A Condition (If/Else) action makes a macro decide what to run based on what’s true at the moment it reaches the action. Conditions can test expressions or the screen (pixels, OCR text, images). For random branching, use the conditional’s weighted random Branching Mode.
Overview
Section titled “Overview”In the + Add Action menu, under Variables & Logic, Condition (If/Else) adds a structured action with one or more branches:
- If – run these children when the condition is true.
- Else if – additional alternative branches (you can add as many as you like).
- Else – run these children when nothing above matched.
You can nest conditionals freely. A common pattern is a single If for a happy path with an Else that handles the unhappy one.
How to use
Section titled “How to use”- Click + Add Action → Condition (If/Else).
- Configure the first If branch’s condition (see Condition types below).
- Add children to the If branch.
- Optionally add more Else if branches with their own conditions.
- Optionally add children to the Else branch – they run when nothing above matches.
Branching Mode
Section titled “Branching Mode”Every conditional runs in one of two modes. You pick the mode when creating the conditional, and you can change it any time in the conditional’s settings dialog.
Individual (the default)
Section titled “Individual (the default)”Each branch has its own condition. At playback the conditions are checked top to bottom, the first matching branch runs, and the final Else runs when nothing matched.
Random (weighted)
Section titled “Random (weighted)”The conditional has no conditions at all – instead it has 2–10 paths, and playback picks exactly one path at random:
- Number of options sets how many paths exist (2–10).
- By default every path is equally likely – three paths means 33.33% each.
- Turn on Adjust weights manually to give each path its own percentage (up to two decimals). The weights must add up to exactly 100% – the dialog shows the running total in green or red and won’t save until it’s exact.
Use it for A/B-style variation: “80% of runs do the normal flow, 20% take the alternative.”
Switching modes keeps your actions: going from Individual to Random keeps every branch and its children as paths; going from Random to Individual turns the paths into If / Else if branches with a placeholder true expression (and the last one into Else) so you can put real conditions in. One thing to watch: reducing the Number of options removes the extra paths including the actions inside them.
Condition types
Section titled “Condition types”Every branch (except Else) has a condition. There are four condition types: Expression, Color, Text, and Image.
1. Expression
Section titled “1. Expression”A JavaScript boolean expression. Examples:
{counter} > 10{role} === "admin"Math.random() < 0.5
Full reference: Variables and Expressions.
2. Pixel color
Section titled “2. Pixel color”Reads the color at a single screen coordinate and matches it against a target. The editor uses the same sections as Check Color: Where to look, What to find, and Check.
| Field | What it does | Default |
|---|---|---|
| X | Horizontal screen coordinate to read. | 0 |
| Y | Vertical screen coordinate to read. | 0 |
| Sample | Opens the macOS color sampler; clicking a pixel fills in X, Y, and the color. | – |
| Color / Hex | The target color, as a color picker plus an editable hex value. | White |
| Tolerance (per channel) | How close per channel a pixel must be to count as matching (0–255). | 10 |
| Mode | Check once – if color is there / Check once – if color is not there (single instant check) or Wait – until color is there / Wait – until color is gone (polls until the condition is met or Wait up to runs out). | Check once – if color is there |
| Wait up to (ms) | How long to keep checking before giving up. Only shown for the two “Wait – …” modes. | 10000 |
| Check every (ms) | Time between checks. Only shown for the two “Wait – …” modes. | 500 |
The tolerance works exactly as in Check Color.
3. Text in area (OCR)
Section titled “3. Text in area (OCR)”Runs OCR on a screen region and tests the recognized text. The editor uses the same Where to look, What to find, and Check structure as Find Text, but it only decides which branch runs. To also save the text, add Save Text… from the branch’s Special Actions menu.
| Field | What it does | Default |
|---|---|---|
| Where to look | Fixed area, Current Monitor, Specific Monitor, or Window (including Current Window) – same choices as the Find Text action. Monitor and window targets are resolved fresh when the condition runs; a Window target is also brought to the front first so it isn’t covered by another window. | Fixed area |
| Area | The screen rectangle to OCR when Where to look is Fixed area. X, Y, width, and height accept Number expressions evaluated when the condition runs. | – |
| Mode | Text searches for visible words exactly as typed, Expression evaluates a JavaScript expression first, and Regex treats the input as a regular expression pattern. | Text |
| Text to find / Pattern to find | The text, expression, or regex pattern to search for. The small Aa button makes matching case-sensitive. | Case-insensitive |
| Match style | How the target can appear inside a single recognized text item: Anywhere, Whole word, or Appears alone. | Anywhere |
| Test | Runs OCR against the current area, reports the number of matches, and highlights the exact characters of the first match for 5 seconds. | Optional |
| Mode | Check once – if text is there / Check once – if text is not there or Wait – until text is there / Wait – until text is gone. | Check once – if text is there |
| Wait up to (ms) | How long to keep checking before giving up. Only shown for the two “Wait – …” modes. | 10000 |
| Check every (ms) | Time between checks. Only shown for the two “Wait – …” modes. | 500 |
| Language | In the collapsed-by-default Advanced Text Recognition section (scroll down in the editor if not visible): Use General Setting follows Settings → General → Default OCR Language dynamically. Automatic detects the language for this condition. | Use General Setting |
| Recognition Style | In Advanced Text Recognition: Default uses language correction; Focused on codes & numbers avoids language-based correction or refinement for exact character sequences. | Default |
For Match style, Anywhere finds the letters anywhere in visible text, Whole word requires the target to be its own word, and Appears alone requires the full recognized text item to be exactly the target (no other characters directly in front / behind). For a visual example click on the info button next to Match style.
When Run Settings → Advanced → Highlight screen-reading areas is enabled, Text-in-area and Image-in-area conditions also show their active search area during playback.
4. Image in area
Section titled “4. Image in area”Searches for a reference image inside a screen region.
| Field | What it does | Default |
|---|---|---|
| Where to look | Fixed area, Current Monitor, Specific Monitor, or Window (including Current Window) – same choices as the Find Image action. Monitor and window targets are resolved fresh when the condition runs; a Window target is also brought to the front first so it isn’t covered by another window. | Fixed area |
| Search area | The screen rectangle to scan inside when Where to look is Fixed area. X, Y, width, and height accept Number expressions evaluated when the condition runs. | – |
| Reference Image | The image to look for. Captured or imported as PNG/JPEG/TIFF. Stored inside the macro file. Imported Retina screenshots are scaled to screen size automatically, and matching tolerates size differences up to 2x and uniform brightness shifts – see Find Image’s Notes & limitations. | – |
| Similarity threshold | A value from 0% to 100%. Higher means stricter; 100% is pixel-identical. In most cases between 80% and 90% is perfect. | 90% |
| Mode | Check once – if image is there / Check once – if image is not there or Wait – until image is there / Wait – until image is gone. | Check once – if image is there |
| Wait up to (ms) | How long to keep checking before giving up. Only shown for the two “Wait – …” modes. | 10000 |
| Check every (ms) | Time between checks. Only shown for the two “Wait – …” modes. | 500 |
The condition editor’s Test button behaves exactly like Find Image’s, including the multi-match overlays – see Testing the match.
Wait variants
Section titled “Wait variants”Pixel, Text, and Image conditions all offer the same four Mode options as the Find actions. The two “Check once” modes read the screen exactly once and immediately pick a branch. The two “Wait” modes re-check on the Check every interval until the condition is met; if Wait up to runs out first, the condition counts as false and the next branch (or Else) runs – exactly like a Find action falling into its Else branch. The “…is not there” and “…is gone” modes make the condition true when the target is absent. Coordinate shifts from Shift Coordinates apply to these conditions the same way they apply to Find actions.
Branch special actions
Section titled “Branch special actions”Every If / Else-if / Else row shows a Special Actions menu. What it offers depends on the branch.
An If / Else-if branch whose condition is Color, Text, or Image behaves like the branch of a Find action that found its target, so its menu adds Interact with Area…, Save Coordinates…, and (for Text conditions) Save Text… – acting on the area the condition matched, with the same Target Area choices and dialogs as inside Find actions. The Else branch and branches with an Expression or Random condition have no matched area, so those three entries are not offered there.
Show Error Dialog… is offered in every branch, and may be added as often as you like. It pauses the run and asks: Continue Macro runs the rest of the branch, Stop Macro ends the run, and Run branches again re-tests the conditional from the first If downwards.
Running the branches again is offered even when no condition looks at the screen. Nothing runs while the dialog is open, so an Expression or Random condition can only come out the same way and the dialog will simply return – the option is still there rather than being taken away.
The dialog’s message names what the branch checked, you can add your own text underneath it, it can answer itself after a timeout, and it reaches Slack with the same three buttons. More on this dialog: Find Image → Show Error Dialog.
Weighted-random paths (“Path 1”, “Path 2”, …) have no condition to re-test and carry no special actions at all.
Under a Text condition, those three area-based special actions also have the same Advanced targeting mode as Find Text. Its pill sits in the dialog header. When enabled, the selected Exact characters, Full word, Whole text group, or Full search area remains in a separate Reference Area section and becomes the actual reference rectangle and text.
When you turn on Advanced targeting, more detailed controls appear:
| Control | What it does |
|---|---|
| Nearby text or Custom area | The two kinds of target. Nearby text takes the text right next to what was found – for example the number beside a label. Custom area takes a rectangle at a fixed spot relative to what was found: pick one of nine anchor points, then set the offsets and the size (Number expressions work too). The rows below are for Nearby text. |
| Where is the text? | Sets the direction from the reference: After area, Before area, Above area, Below area, Before & After area, or Above & Below area. |
| What to select | How much text to take: Next text item, Next characters, Characters at positions, Next words, Words at positions, Rest of row, Entire adjacent row, a number of Rows, or Text matching Regex. |
| Position field | Position 1 is nearest to the Reference Area, and every requested position must exist. Enter one position or one continuous range such as 3–6. Comma-separated, split selections are rejected so the result stays one target area. The info button explains the accepted formats. Invalid entries show a red explanation below the row. |
| Include text of match | Optionally adds the reference text itself to the result. |
| More options | A collapsed area for filters and punctuation handling. |
Nearby selection stays inside the original condition search area unless Full search area is the reference. The whole condition area is then the reference, so nearby text is searched outside it. Advanced targeting is off by default and remains unavailable under Color and Image conditions.
The special rows follow the same rules as in Find branches: they can be nested inside groups and conditionals within their branch, but can’t be moved, dragged, or pasted outside of it. Selecting one outlines the branch row it belongs to – inside a Conditional the condition sits on the branch, not on the Conditional itself, so that is the row the action refers to.
Pasting is held to the same rule as the menu: an Interact with Area, Save Coordinates, or Save Text pasted into a branch without a screen condition – the Else, or an Expression or Random branch – is refused with “Interact with Area needs a branch that checks the screen for text, an image, or a color.” Show Error Dialog can be pasted into any of them.
Area-based special-action dialogs can test their parent condition before playback. Under a Text condition, the collapsible area example is followed by Show Area, which runs OCR once and outlines the selected Exact characters, Full word, Whole text group, or Full search area scope. With Advanced targeting enabled, this source preview remains under Reference Area, while the result section has its own Show Area. Orange marks the reference and teal marks the advanced target there. Save Text → Test runs the same parent condition and displays exactly the text that the selected scope or advanced target would save, with selectable output and a copy button. Interact with Area also offers Show and Show & click (or Show & move) to mark the resolved area and offset anchor point, optionally performing the selected interaction. Image conditions use the winning image rectangle, while Color conditions use their 1×1 pixel area. Save Coordinates → Test shows the area and top-left crosshair and reports only the selected property value – the same number that playback saves.
These are one-shot previews even when the parent condition uses a Wait mode. If text or an image is not currently found, ClicKey reports that no preview area is available instead of substituting made-up character, word, or image bounds. If an Advanced targeting preview finds the Reference Area but cannot resolve its target, it still outlines the Reference Area in orange while reporting the target error. Coordinate and offset expressions use variable default values in editor previews.
Changing the condition type with special actions in the branch
Section titled “Changing the condition type with special actions in the branch”When you edit a branch condition and switch its type, existing special actions in that branch are handled like this:
- Between Color, Text, and Image everything keeps working – these conditions all produce a found area. Only Save Text needs a Text condition; see below. The Target Area choice of Interact with Area / Save Coordinates is text-specific: under Color and Image it is hidden and the whole match area is used, but the stored choice is kept – switch back to Text and your previous selection (for example Exact characters) is restored. Actions added under a Color or Image condition use each action’s own default when the branch later becomes Text (Interact with Area: Full word; Save Coordinates: Whole text group).
- When at least one special action stops fitting – Save Text when leaving Text, or Interact with Area / Save Coordinates when switching to Expression or Random – saving asks before committing, for example: “Delete the “Save Text” action?” – Changing the condition from Text → Image means the “Save Text” action in this branch no longer fits. With several affected actions the prompt lists them with counts. Delete Action(s) (the default) removes them together with the type change in a single undo step. Keep & Mark Red keeps them, for example for testing purposes; they are marked as errors (counted in the warnings bar, with the reason shown on the row’s error indicator) and skipped during playback until the condition fits them again – switch the type back and the marking disappears by itself.
How to use – Else if and Else
Section titled “How to use – Else if and Else”Each conditional has:
- One If branch (always present).
- Zero, one or more Else if branches, each with its own condition.
- One Else branch (no condition; runs when nothing above matched).
Branches are evaluated in order, top to bottom. The first matching branch wins; the rest are skipped. The Else branch runs only when no condition above matched.
The Else branch can be turned into a regular condition branch with the Make Else If button on its row. A new Else branch is created below it, and the actions stay where they were.
Reordering and reusing branches
Section titled “Reordering and reusing branches”If and Else if rows can be rearranged and reused like actions:
| What | How |
|---|---|
| Move up / down | ⌘↑ / ⌘↓, the right-click menu, or drag the branch row |
| Copy / paste | ⌘C / ⌘V or the right-click menu |
| Duplicate | ⌘D – the copy lands directly below the original, with the same condition |
| Cut / delete | ⌘X / ⌘⌫ – removes the branch including the actions inside it |
| Edit the condition | Double-click the branch row, or Edit Condition… in the right-click menu |
Rules that always hold:
- The order stays valid. The first condition branch is the If and the Else is always last. Move the first Else if up and it simply becomes the If, while the previous If becomes an Else if – the labels follow the position.
- A conditional always keeps one condition branch and its Else. When only those two are left, Cut, Delete, and the move commands are greyed out.
- The Else can’t be moved, copied, or deleted – there can only be one, and it always stays last. Use Make Else If to turn it into a condition branch.
- Branches can be pasted into any Conditional that uses If / Else, including a different one. Pasting a branch anywhere else – a Random (weighted) conditional, a Find action’s branches, a group, or the main list – is refused with a short message.
Pasted and duplicated branches bring their actions with them.
Notes & limitations
Section titled “Notes & limitations”- Branches are evaluated top to bottom. The first match wins. Reorder branches to change priority.
- OCR conditions need Screen Recording permission. Same for color and image conditions. Without it the condition errors and the macro stops.
- The OCR Regex input uses standard regular expressions. Anchors (
^,$), classes, quantifiers, groups – all work. Test your pattern; OCR returns whitespace and line breaks that can affect anchoring. - Image conditions store the reference image inside the macro file. Macros with many reference images can be surprisingly large. That’s expected and keeps the file self-contained.
- Text conditions can save the text they found. Add Save Text… from the branch’s Special Actions menu.
- Conditions can click what they found. Add Interact with Area… from the branch’s Special Actions menu.
Related
Section titled “Related”- Variables and Expressions – how Expression conditions work.
- Check Color – the same color check as an action of its own.
- Find Text – the same text check as an action of its own.
- Find Image – the same image check as an action of its own.
- Groups, Loops, and Repeats – While / Until use the same condition types.
- Set Variable – change variables before a Conditional decides.