JavaScript automation

Build repeatable location sequences with Wormhole Script

Wormhole Script runs JavaScript in a restricted environment and exposes only six location functions. Use normal variables, functions, arrays, conditions, loops, JSON, dates, regular expressions, and math.

Your first script

Create or select a project in the Script tab, paste this example, and choose Run:

MoveTo(39.9042, 116.4074);
MoveUp(10);
MoveRight(10);
MoveDown(10);
MoveLeft(10);

MoveTo establishes the starting coordinate. Every relative movement function in the same run uses the result of the previous command. Wormhole sends commands to the selected device one at a time.

Always call MoveTo first before using a relative movement function.

Location API

FunctionEffect
MoveTo(latitude, longitude)Sets the absolute starting coordinate.
MoveUp(meters)Moves north by the requested distance.
MoveDown(meters)Moves south by the requested distance.
MoveLeft(meters)Moves west by the requested distance.
MoveRight(meters)Moves east by the requested distance.
Move(northMeters, eastMeters)Moves both axes in one command. Negative values move south or west.

Coordinates and distances must be finite numbers. Latitude must be between −90 and 90, and longitude between −180 and 180. For compatibility with saved scripts, an omitted function argument is treated as zero.

Use normal JavaScript logic

This example combines an array, a loop, a function, and Math:

function moveEastInSteps(distances) {
  for (const meters of distances) {
    MoveRight(Math.max(1, meters));
  }
}

MoveTo(39.9042, 116.4074);
moveEastInSteps([2, 3, 5]);
Move(-4, 6);

Standard language features such as Map, Set, Date, RegExp, JSON, and Math are available.

Create and save a project

  1. Open the Script tab and choose New.
  2. Enter a project name and optional description.
  3. Write or paste the source code.
  4. Choose Save to keep the project.
  5. Select the intended device, then choose Run.
Wormhole Script editor with project list, JavaScript source, Run, Stop, and log

Stop a script safely

Choose Stop to cancel a running script. Cancellation interrupts both long-running JavaScript and the delay between device movements. The app also applies execution, statement, memory, and recursion limits so faulty scripts cannot run without bounds.

// This loop is intentionally endless for a cancellation test.
// Run it only when you are ready to press Stop.
while (true) {
  // Wormhole will interrupt this safely.
}

What the sandbox does not expose

Wormhole Script is JavaScript control logic, not unrestricted access to your computer. It does not expose:

  • .NET or other CLR objects and reflection.
  • Files, folders, environment variables, or processes.
  • Network requests, sockets, or browser objects.
  • Node.js modules such as require or process.
  • Browser timers such as setTimeout.

This boundary is the same on Mac and Windows and keeps scripts compatible with the Mac App Store sandbox.

Common errors

Message or symptomWhat to check
“Please call MoveTo first”Add MoveTo(latitude, longitude) before relative movement.
Coordinate range errorCheck latitude, longitude, and decimal separators.
Syntax errorCheck brackets, quotes, commas, and function spelling.
No device selectedReturn to Location, refresh the device list, and select the USB-connected device.
Script stoppedThe Stop button, page navigation, or an execution safety limit cancelled the run.

After a script test, stop the run and use Restore on the Location tab.