Skip to content

Embedded Macros

ClicKey Pro

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.

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.

  1. Click + Add Action → Embed Macro File.
  2. Pick the .json macro file.
  3. Optional: click Nested Variables on the embed row to give the embedded macro’s variables your own starting values (see Variable overrides).
  4. Optional: click Return Variables to copy values from the embedded macro back into your macro’s variables when it finishes (see Return variable mappings).

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 fieldWhat it does
VariableOne of the embedded macro’s variables.
ExpressionA 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:

  • recipient with {currentCustomerEmail} (parent variable)
  • body with "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 fieldWhat it does
Embedded variableOne of the embedded macro’s variables.
Parent variableThe 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.

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.

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.

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.

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).

ActionDirect embedNested embedNotes
Open Macro in New WindowYesYesOpens the embedded .json in a new ClicKey window. Disabled when the file is missing.
Show in FinderYesYesReveals the embedded .json in Finder. Disabled when the file is missing.
Refresh / Refresh All FilesYesNoRe-reads the embedded file from disk. Refresh All re-reads every embed in the parent.
Relink with New File…YesNoSwap 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 missingNoFinds 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.

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.

OptionWhat it doesDefault
Embedded fileThe .json macro file to embed.–
Nested VariablesStarting values for the embedded macro’s public variables – a value or expression per variable.Empty – each variable starts at its default
Return VariablesWhich parent variable gets each embedded variable’s final value.Not mapped
  • 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.