Utilities

Logging, screen info, flow control, and macro invocation

print(...values)

Displays a message in the macro status / log output. Accepts any number of arguments — they are converted to strings and joined with a space, matching console.log behaviour.

ParameterTypeDescription
valuesanyOne or more values to display

Returns void

print("counter:", getGlobalVar("counter"));
print("pos:", pos.x, pos.y);
print("done");

getScreenSize()

Returns the physical screen dimensions in pixels. Useful for writing device-agnostic scripts that position elements relative to screen size.

Returns {w: number, h: number} — width and height of the screen in physical pixels

var screen = getScreenSize();
tapAt(screen.w / 2, screen.h / 2); // tap the center

// Relative positioning
tapAt(screen.w * 0.1, screen.h * 0.9); // bottom-left area

exit()

Immediately stops the macro. Equivalent to the user pressing Stop — the run is marked as completed, not as an error.

Returns never — execution halts at this call and never continues past it

if (getGlobalVar("retries") >= 5) {
  print("giving up");
  exit();
}

// Also useful as a clean stop at the end of a conditional branch
if (ocr("status") === "done") exit();

callMacro(idOrName)

Runs another macro synchronously by its ID or name. Blocks until the called macro finishes.

It runs one pass of the target's steps, ignoring the target's own loop mode, so control always comes back to you even if the target is set to loop forever. (The visual Start Macro step is a different thing: that one is a handoff which honors the target's loop mode and never returns to the calling macro.)

ParameterTypeDescription
idOrNamestringThe macro's internal ID or name, as shown in the macro list. Matching is exact and case-sensitive — there is no fuzzy or partial lookup.

Returns boolean — true if a matching macro was found and run; false if no macro matched the id. A macro cannot call itself: the running macro is excluded from the lookup, so a self-call returns false rather than recursing.

if (!callMacro("abc-123-def")) {
  print("macro not found");
}
Not always defined. The dispatcher is generated only when the app holds at least one macro other than the one running. In an app whose only macro is this one, callMacro does not exist at all, and calling it throws a ReferenceError that aborts the macro instead of returning false. If your script might ship as an app's only macro, guard it:
if (typeof callMacro === "function" && callMacro("cleanup")) {
  print("cleanup ran");
}