Quick Start
Scripting allows you to define custom iOS Intents using an intent.tsx file. These scripts can receive input from the iOS share sheet or the Shortcuts app and return structured results. With optional UI presentation, you can create interactive workflows that process data and deliver output dynamically.
1. Creating and Configuring an Intent
1.1 Create an Intent Script
- Create a new script project in the Scripting app.
- Add a file named
intent.tsxto the project. - Define your logic and optionally a UI component inside the file.
1.2 Configure Supported Input Types
Tap the project title in the editor’s title bar to open Intent Settings, then select supported input types:
- Text
- Images
- File URLs
- URLs
This configuration enables your script to appear in the share sheet or Shortcuts when matching input is provided.
2. Accessing Input Data
Inside intent.tsx, use the Intent API to access input values.
Example:
3. Returning a Result
Use Script.exit(result) to return a result to the caller, such as the Shortcuts app or another script. Valid return types include:
- Plain text:
Intent.text(value) - Attributed text:
Intent.attributedText(value) - URL:
Intent.url(value) - JSON:
Intent.json(value) - File path or file URL:
Intent.file(value)orIntent.fileURL(value)
Example:
4. Displaying Interactive UI
Use Navigation.present() to show a UI before returning a result. You can render a React-style component and then call Script.exit() after the interaction completes.
Example:
5. Using Intents in the Share Sheet
If a script supports a specific input type (e.g., text or image), it will automatically appear as an option in the iOS share sheet:
- Select content such as text or a file.
- Tap the Share button.
- Choose Scripting in the share sheet.
- Scripting will list scripts that support the selected input type.
6. Using Intents in the Shortcuts App
You can call scripts from the Shortcuts app with or without UI:
- Run Script: Executes the script in the background.
- Run Script in App: Executes the script in the foreground, with UI presentation support.
Steps:
- Open the Shortcuts app and create a new shortcut.
- Add the Run Script or Run Script in App action from Scripting.
- Choose the target script and pass input parameters if needed.
7. Intent API Reference
Intent Properties
Intent Methods
8. Best Practices and Notes
- Always call
Script.exit()to properly terminate the script and return a result. - When displaying a UI, ensure
Navigation.present()is awaited before callingScript.exit(). - Use "Run Script in App" for large files or images to avoid process termination due to memory constraints.
- You can use
queryParameterswhen launching scripts via URL scheme if additional data is needed.
