Script

The Script module provides context and utility functions for managing script execution in the Scripting app. It enables you to access runtime metadata, terminate scripts with results, run other scripts programmatically, and construct URL schemes to launch or open scripts.


Properties

name: string

The name of the currently running script.

1console.log(Script.name) // e.g., "MyScript"

directory: string

The directory path where the script is located.

1console.log(Script.directory) // e.g., "/private/var/mobile/Containers/..."

widgetParameter: string

The parameter passed when the script is launched from a widget.

1if (Script.widgetParameter) {
2  console.log("Widget input:", Script.widgetParameter)
3}

queryParameters: Record<string, string>

Key-value pairs parsed from a run URL scheme.

1// URL: scripting://run/MyScript?user=John&id=123
2console.log(Script.queryParameters.user) // "John"
3console.log(Script.queryParameters.id)   // "123"

Methods

Script.exit(result?: any | IntentValue): void

Ends the script and optionally returns a result. This is required to release resources properly.

  • result: Any value or IntentValue object to return to the caller (e.g., Shortcuts or another script).
1Script.exit("Done")
2
3// or return structured value
4Script.exit(Intent.json({ status: "ok" }))

Script.run<T>(options: { name: string; queryParameters?: Record<string, string>; singleMode?: boolean }): Promise<T | null>

Runs another script programmatically and waits for its result.

  • name: The name of the script to run.
  • queryParameters: Optional data to pass.
  • singleMode: If true, ensures only one instance of the script runs.

Returns: the value passed from Script.exit(result) in the target script.

1const result = await Script.run({
2  name: "ProcessData",
3  queryParameters: { input: "abc" }
4})
5
6console.log(result)

Script.createRunURLScheme(scriptName: string, queryParameters?: Record<string, string>): string

Creates a scripting://run URL to launch and execute a script.

1const url = Script.createRunURLScheme("MyScript", { user: "Alice" })
2// "scripting://run/MyScript?user=Alice"

Script.createRunSingleURLScheme(scriptName: string, queryParameters?: Record<string, string>): string

Creates a scripting://run_single URL that ensures only one instance of the script runs.

1const url = Script.createRunSingleURLScheme("MyScript", { id: "1" })
2// "scripting://run_single/MyScript?id=1"

Script.createOpenURLScheme(scriptName: string): string

Creates a scripting://open URL to open a script in the editor.

1const url = Script.createOpenURLScheme("MyScript")
2// "scripting://open/MyScript"

Script.createDocumentationURLScheme(title?: string): string

Generates a URL to open the documentation page in the Scripting app.

  • title: Optional. If provided, opens a specific documentation topic.
1const url = Script.createDocumentationURLScheme("Widgets")
2// "scripting://doc?title=Widgets"

Notes

  • Always call Script.exit() to properly terminate a script and free memory.
  • Use Script.run() to chain or modularize scripts and retrieve structured results.
  • URL schemes can be used in external apps (like Shortcuts) to trigger scripts with parameters.
  • singleMode is recommended for scripts that must not run in parallel.

This API allows you to build reusable script logic, trigger automation via custom URL schemes, and manage inter-script communication in a structured and efficient manner.