Script
Entry point for widget rendering and Shortcuts integration
The entry point. Script.setWidget() registers the root widget; Script.return() passes a value back to Shortcuts.
Properties
inputAnyWhat was handed to this run, or null when nothing was.
actions[Any]Actions queued since the last run, oldest first.
Methods
Script.setWidget(widget)Set the widget to be rendered.
- widget WidgetNode required
Script.return(value)Set the return value for headless script execution.
- value Any required
Anything JSON can represent. A headless run hands it back to whatever started the script.
Script.onAction(handler)Runs the handler once for every action in Script.actions, in order. Call it before you build your widget.
- handler fn(action: ?) required
Called once for every queued action, in order. It receives the action:
- name String
The action string set on the Button or Toggle that was tapped.
- payload Any
Whatever that component attached to it, or null.
- name String
Examples
Basic widget script
const widget = new Widget({
child: Text("Hello, World!")
});
Script.setWidget(widget);Shortcuts integration
// Receive input from Shortcuts via Widget.parameter
const input = Number(Widget.parameter) || 0;
const result = input * 2;
// Return the result to Shortcuts
Script.return(result);