Embedded Macros
Embedded Macros
Section titled “Embedded Macros”Want to reuse a workflow in more than one macro? Add an Embed Macro File action. It runs another macro’s actions as part of this one, and each parent macro can pass in its own values.
Overview
Section titled “Overview”In the + Add Action menu, under Environment, Embed Macro File opens a Finder dialog right away, where you pick another .json macro file on your drive.
When the parent macro reaches the embed, the embedded macro’s actions run right there, as part of the parent’s run. The embed row has two buttons: Nested Variables passes values in, Return Variables gets values back.
How to use
Section titled “How to use”- Click + Add Action → Embed Macro File.
- Pick the
.jsonmacro file. - Optional: click Nested Variables on the embed row to give the embedded macro’s variables your own starting values (see Variable overrides).
- Optional: click Return Variables to copy values from the embedded macro back into your macro’s variables when it finishes (see Return variable mappings).
Variable overrides (passing values in)
Section titled “Variable overrides (passing values in)”The embedded macro has its own variables (if configured). By default, each one starts at its default value when the embedded macro runs.
You can override that: provide a value or a JavaScript expression that replaces the original default starting value. Do this in Nested Variables on the embed row – next to each variable you see the Effective value it will start with. Variables of macros embedded further down appear in the same list, under their file name.
In order to make this work, the variables configured in the embedded macro need to be public variables (the default).
| Override field | What it does |
|---|---|
| Variable | One of the embedded macro’s variables. |
| Expression | A value or a JavaScript expression that evaluates to a value of the variable’s type. This can also reference the parent’s variables ({parentVar}). |
Example: an embedded send-message.json defines recipient and body. The parent can override:
recipientwith{currentCustomerEmail}(parent variable)bodywith"Order shipped: " + {orderId}
Return variable mappings (getting values back)
Section titled “Return variable mappings (getting values back)”When the embedded macro finishes, the values of its variables can be copied back into the parent’s variables. Set this up in Return Variables on the embed row: for each variable of the embedded macro, pick the parent variable that gets its value – or leave it Not mapped.
| Mapping field | What it does |
|---|---|
| Embedded variable | One of the embedded macro’s variables. |
| Parent variable | The parent variable that gets the value. Only variables of the same type are offered. |
Example: embedded read-balance.json reads a number off the screen into a number variable balance. The parent macro maps it to {customerBalance} (a variable configured in the parent macro) and uses it in the next step.
Public versus private variables
Section titled “Public versus private variables”Each variable in a macro has a Public switch, set in the Variables panel.
- Public variables (the default) are visible to a parent macro that embeds this one. They can be input-overridden and return-mapped.
- Private variables (Public off) can’t be overridden by the parent – they are for internal use in the embedded macro. A return mapping can still copy their final value back.
Embeds inside embeds
Section titled “Embeds inside embeds”An embedded macro can embed other macros, too. What it can’t do is loop back – a macro that embeds itself, or a chain like A → B → A. ClicKey refuses to add, paste, or relink an embed that would close such a loop, and tells you which files form it.
Copying an embed into another macro
Section titled “Copying an embed into another macro”When you copy an embed and paste it into another macro, its Nested Variables and Return Variables settings come with it. They use the parent’s variables, so if the other macro doesn’t have them, the Resolve Pasted Variables dialog opens – like for any pasted action. Create the missing variables, pick replacements, or fix the expression. A cleared override is dropped (the embedded macro then uses its own default), and a return mapping can be set to (none). See Repairing broken expressions.
Row actions and the context menu
Section titled “Row actions and the context menu”Right-click an embed row to act on it. The available items depend on whether the embed is a direct embed (one you added to the macro you’re editing) or a nested embed (an embed living inside another embedded file).
| Action | Direct embed | Nested embed | Notes |
|---|---|---|---|
| Open Macro in New Window | Yes | Yes | Opens the embedded .json in a new ClicKey window. Disabled when the file is missing. |
| Show in Finder | Yes | Yes | Reveals the embedded .json in Finder. Disabled when the file is missing. |
| Refresh / Refresh All Files | Yes | No | Re-reads the embedded file from disk. Refresh All re-reads every embed in the parent. |
| Relink with New File… | Yes | No | Swap this embed’s target file for a different .json. Available whether the current file resolves or not – pick it to replace an embed without first deleting the row. |
| Search for File… | Only when missing | No | Finds a missing file again, even if it was renamed: search a folder (subfolders included) or pick the file directly. A folder search also reconnects other missing embeds it finds. |
Nested embeds don’t expose Refresh, Relink, or Search because those actions would write into the parent embed file – which you’re not editing in the current window. To change them, open the parent embed in its own window (right-click → Open Macro in New Window) and edit it there.
Switching actions off for now
Section titled “Switching actions off for now”The embedded macro’s actions are read-only in the parent. One thing works anyway: you can switch actions off – and on again – for the moment. Select them and press ⌘H, or right-click → Disable.
ClicKey asks first, because this change is temporary. It counts for every run while the macro is open, but it is not saved – not in the parent, and not in the embedded file. A blue info icon marks each changed action and the embed row. To undo it, right-click the action → Reset to Original.
To switch an action off for good, change it in the embedded macro file. To decide per run, put it in a Conditional in the embedded macro that checks a variable, and set that variable from the parent with Nested Variables.
Options & settings
Section titled “Options & settings”| Option | What it does | Default |
|---|---|---|
| Embedded file | The .json macro file to embed. | – |
| Nested Variables | Starting values for the embedded macro’s public variables – a value or expression per variable. | Empty – each variable starts at its default |
| Return Variables | Which parent variable gets each embedded variable’s final value. | Not mapped |
Notes & limitations
Section titled “Notes & limitations”- The embedded file stays on your drive. ClicKey reads it from there, so changes to the file show up in every parent. If the file is gone, ClicKey tells you when you open the macro, the row turns orange, and the embed runs nothing until you find the file again with Search for File….
- The parent’s Run Settings apply. The embedded macro’s own speed, loops, and capture settings are ignored while it runs as an embed.
- The embedded macro’s actions are read-only in the parent. They appear under the embed row, like a group’s. To change them, open the embedded file (right-click → Open Macro in New Window) – only switching actions off for now works from the parent.
- Overrides that no longer fit are flagged. If a variable in the embedded macro is deleted, turned private, or changes its type, the Nested Variables button shows a count, and the dialog lists the override under Unavailable Overrides, where you can Discard it. Return Variables does the same under Unavailable Mappings.
- The parent’s Variables panel shows only the parent’s own variables. The embedded macro’s variables are in Nested Variables and Return Variables on the embed row.
Related
Section titled “Related”- Variables and Expressions – defines what a variable is, and what an expression can do in the override fields.
- Set Variable – set up variables in the parent before passing them in.
- How Macros Work – the mental model that includes embedded macros.
- File Format – how macros are saved.
- Conditional Branches – wrap embeds in conditionals to call different sub-macros under different circumstances.