Run script
Run a small JavaScript snippet that can read and change variables.
- Where
- + Add actionSystemRun script
- Wait
- Has a Wait switch: on, the next action starts once this one is done

Run script is the glue between actions. When a condition is not enough, a few lines of JavaScript can do maths, format text, pick a value out of a JSON answer or keep a counter.
Settings
Section titled “Settings”| Setting | What it does |
|---|---|
| Code | The JavaScript to run. |
| Save result to | Stores the result in this variable. |
| Scope | This run or Everywhere, see variables. |
| Run test | Runs the snippet now and shows the result, how long it took and which shared variables it would change. |
What the script sees
Section titled “What the script sees”| Name | Contains |
|---|---|
vars.name |
Every variable the macro can see: the trigger values, shared variables and this run’s variables (this run’s win over shared ones). |
globals.name |
Only the shared variables. |
velocity, velocity01, pressure, pressure01, x, y |
The trigger values, as numbers. |
pageId |
The page of the button, as text. |
All variables are text. Turn them into numbers before doing maths: Number(vars.count) + 1.
How it runs
Section titled “How it runs”- The result is the value of the last expression, or what you
return. As soon as the wordreturnappears anywhere in the code, even in a comment or a string, the snippet runs as a function body, so it needs an explicitreturnto have a result. - Assigning
vars.name = ...sets a variable for this run. Assigningglobals.name = ...sets a shared variable. - Text results are saved as they are, whole numbers without decimals, objects and arrays as JSON. No result saves an empty text.
- The snippet runs in a sandbox: plain JavaScript without a console, network or file access. Loops stop after 2,000,000 rounds and nesting after 256 calls, so a runaway loop ends with an error instead of hanging Lunchpad.
- An error is noted in the log and the macro goes on. The Save result to variable is not changed.
- With Wait on, the next actions see the result and the changed variables.
Examples
Section titled “Examples”A death counter that says something useful (shared variable deaths, result saved to message):
globals.deaths = Number(globals.deaths || 0) + 1;return globals.deaths === 1 ? "First death!" : `Death number ${globals.deaths}`;Pick a value out of an HTTP request answer saved as weather:
return JSON.parse(vars.weather).main.temp > 25 ? "hot" : "fine";Related
Section titled “Related”- Set variable and Add to variable — simple cases without code
- Condition — branch on the result
- Variables and placeholders