Actions
Actions are Chute's bridge to Siri Shortcuts. Each action declaration maps a function-like call to a specific Shortcuts action identifier.
Chute ships with a standard library of ~50 built-in actions covering scripting, text, web, sharing, documents, calendar, contacts, maps, media, settings, and health. You can also declare your own actions for Shortcuts actions not yet in the standard library.
Declaring actions
An action declaration specifies:
- A callable name
- Parameters with external labels (the Shortcuts parameter key) and types
- An optional return type
- A runtime identifier (the Shortcuts action ID)
action showAlert(text WFAlertActionTitle: Text) = "is.workflow.actions.alert";Breaking this down:
| Part | Meaning |
|---|---|
showAlert | The name you use to call this action in Chute |
text | The label you use at the call site: showAlert(text: "Hello") |
WFAlertActionTitle | The internal Shortcuts parameter key (written to the compiled plist) |
Text | The parameter type |
"is.workflow.actions.alert" | The Shortcuts action identifier |
Why two names per parameter?
In the Shortcuts app, each action parameter has an internal key like WFAlertActionTitle. These keys aren't user-friendly, so Chute lets you define a readable label (text) that maps to the internal key. You write showAlert(text: "Hello"), and the compiler emits the correct WFAlertActionTitle key in the plist.
Parameters
Multiple parameters
Actions can have multiple parameters, each with their own label and internal key:
action notify(
body WFNotificationActionBody: Text,
title WFNotificationActionTitle: Text
) = "is.workflow.actions.notification";Default values
Parameters can have defaults, making them optional at the call site:
action notify(
body WFNotificationActionBody: Text,
title WFNotificationActionTitle: Text = "Alert"
) = "is.workflow.actions.notification";
notify(body: "Task complete"); // title defaults to "Alert"Return types
Some actions produce a value. Declare this with -> Type:
action ask(prompt WFAskActionPrompt: Text) -> Text = "is.workflow.actions.ask";
const name = ask(prompt: "What's your name?");Actions without a return type don't produce a usable value.
Single-name parameters
When the label and internal key are the same, you can write the name once:
action sendMessage(to: Text, body: Text) = "com.example.send";Attributes
Actions can have attributes that provide extra metadata:
action doThing() = "com.example.dothing"
@retry(enabled: true)
@platform(min: ios17);Attributes use the @name or @name(key: value, ...) syntax and appear after the runtime identifier.
Calling actions
Call an action the same way you call a function, with labeled arguments:
showAlert(text: "Hello!");
notification(body: "Done", title: "Success");
const clipboard = getClipboard();Actions can also be used in pipelines:
const msg = "Hello";
msg |> showAlert;Shadowing the standard library
If you declare an action with the same name as a standard library action, your declaration shadows it:
action showAlert(message: Text) = "custom.alert";
showAlert(message: "custom"); // uses your declaration, not the stdlibExporting actions
Use export to make an action available to other modules:
export action fetchData(url WFURL: Text) -> Text = "is.workflow.actions.downloadurl";Related
- Standard library: built-in actions available in every Chute file
- Functions: user-defined logic (compiles to sub-shortcuts, not Shortcuts actions)
- Pipelines: chaining actions with
|>