hs.shortcuts
ModuleRun and interact with macOS Shortcuts from JavaScript.
This module bridges to the Shortcuts app, letting you enumerate available shortcuts and run them from your Hammerspoon configuration.
Listing shortcuts
const all = hs.shortcuts.list()
all.forEach(s => console.log(s.name + " (accepts input: " + s.acceptsInput + ")"))
Running a shortcut
hs.shortcuts.run("My Shortcut").then(output => {
if (output) console.log("Output: " + output)
}).catch(err => console.log("Error: " + err))
Opening a shortcut for editing
hs.shortcuts.open("My Shortcut")
Properties
This module has no properties.
Methods
hs.shortcuts.list() -> [[String: Any]]
Returns an array of all available shortcuts.
| Key | Type | Description |
|-----|------|-------------|
| `name` | `string` | The display name of the shortcut |
| `id` | `string` | A UUID uniquely identifying the shortcut |
| `acceptsInput` | `boolean` | Whether the shortcut expects input when run |
| `actionCount` | `number` | How many actions the shortcut contains |
Declaration
hs.shortcuts.list() -> [[String: Any]]
Returns
[[String: Any]]
An array of shortcut descriptor objects.
Example
const shortcuts = hs.shortcuts.list()
shortcuts.forEach(s => console.log(s.name))
hs.shortcuts.run(name) -> Promise<string|null>
Runs a Shortcuts shortcut by name and returns any output.
Executes the shortcut in the background via the `shortcuts` CLI tool.
If the shortcut produces output (via a "Stop and Output" action), the
Promise resolves with that string. If the shortcut produces no output,
the Promise resolves with `null`. The Promise rejects if the shortcut
cannot be found or exits with a non-zero status.
Declaration
hs.shortcuts.run(name) -> Promise<string|null>
Parameters
| Name | Type | Description |
|---|---|---|
| name | string | The exact display name of the shortcut to run. |
Returns
Promise<string|null>
A Promise resolving to the shortcut output string, or `null` if the shortcut produced no output.
Example
hs.shortcuts.run("My Shortcut")
.then(output => console.log("Done, output: " + output))
.catch(err => console.log("Failed: " + err))
hs.shortcuts.open(name) -> None
Opens a shortcut in the Shortcuts app for viewing or editing.
Uses the `shortcuts://open-shortcut` URL scheme to bring Shortcuts to
the foreground and navigate directly to the named shortcut.
Declaration
hs.shortcuts.open(name) -> None
Parameters
| Name | Type | Description |
|---|---|---|
| name | string | The display name of the shortcut to open. |
Returns
None
Example
hs.shortcuts.open("My Shortcut")