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.
name: stringThe name of the currently running script.
directory: stringThe directory path where the script is located.
env: stringIndicates the environment in which the current script is running. This allows the script to adapt its behavior based on the runtime context—whether it’s running in the main app, a widget, a notification, or an extension.
| Value | Description |
|---|---|
"index" |
Running in the main app. Entry point is index.tsx. Used for normal UI logic. |
"widget" |
Running in a widget. Entry point is widget.tsx. Used for home screen widgets. |
"control_widget" |
Running in a control widget. Entry point is contrl_widget_button.tsx or control_widget_toggle.tsx. Used for control center widgets. |
"notification" |
Running in the rich notification extension. Entry point is notification.tsx. |
"intent" |
Running as a share sheet or shortcut intent handler. Entry point is intent.tsx. |
"app_intents" |
Running in the App Intents extension. Entry point is app_intents.tsx. |
"assistant_tool" |
Running in the Assistant Tool context. Entry point is assistant_tool.tsx. |
"keyboard" |
Running in the custom keyboard extension. Entry point is keyboard.tsx. |
widgetParameter: stringThe parameter passed when the script is launched from a widget.
queryParameters: Record<string, string>Key-value pairs parsed from a run URL scheme.
metadata: { ... }Metadata of the current script.
icon: The icon of the script. Can be a SFSymbol name.
color: The color of the script. Can be a hex color string like #FF0000 or a CSS color name like "red".
localizedName: The localized name of the script in the current system language.
localizedNames: A record of localized names for different languages. Keys are language codes (e.g., "en", "zh"), and values are the localized names.
description: The description of the script in English.
localizedDescription: The localized description in the current system language.
localizedDescriptions: A record of localized descriptions for different languages.
version: The version string of the script.
author: The script author's metadata:
name: The author's nameemail: The author's email addresshomepage: (optional) The author’s homepagecontributors: An array of contributor objects with the same structure as author
remoteResource: Information about a remote resource for this script:
url: The URL of the remote resource (e.g., a .zip or Git repository)autoUpdateInterval: (optional) The auto-update interval in seconds. If not provided, auto-update is disabled.Script.exit(result?): voidEnds the script and optionally returns a result. This is required to release resources properly.
result?: any | IntentValue: Any value or IntentValue object to return to the caller (e.g., Shortcuts or another script).Script.run<T>(options:): Promise<T | null>Runs another script programmatically and waits for its result.
options.name: The name of the script to run.options.queryParameters: Optional data to pass.options.singleMode: If true, ensures only one instance of the script runs.Returns: the value passed from Script.exit(result) in the target script.
Script.createRunURLScheme(scriptName, queryParameters?): stringCreates a scripting://run URL to launch and execute a script.
Script.createRunSingleURLScheme(scriptName, queryParameters?): stringCreates a scripting://run_single URL that ensures only one instance of the script runs.
Script.createOpenURLScheme(scriptName): stringCreates a scripting://open URL to open a script in the editor.
Script.createDocumentationURLScheme(title?): stringGenerates a URL to open the documentation page in the Scripting app.
title: Optional. If provided, opens a specific documentation topic.createImportScriptsURLScheme(urls): stringGenerates a URL scheme for importing scripts from the specified URLs.
urls: string[]: An array of URLs to import scripts from.hasFullAccess(): booleanDetermine whether user has full access to the Scripting PRO features.
Returns: true if the user has full access to the Scripting PRO features, otherwise false.
Script.exit() to properly terminate a script and free memory.Script.run() to chain or modularize scripts and retrieve structured results.singleMode is recommended for scripts that must not run in parallel.