macotron.shortcuts
List the shortcuts in the Shortcuts app and run one by name.
// Put every shortcut in the launcher.
const names = await macotron.shortcuts.list();
macotron.launcher.set("shortcuts", names.map((name) => ({
id: name,
title: name,
sfSymbol: "square.stack.3d.up",
onClick: () => macotron.shortcuts.run(name),
})));
Shortcuts
Both calls use /usr/bin/shortcuts, the command-line tool that ships with macOS. They run off the main thread.
list(): Promise<string[]>
The names of all your shortcuts. Resolves with [] when there are none or the tool fails.
run(name: string): Promise<boolean>
Runs the shortcut with that name and resolves when it finishes, so a long shortcut keeps the promise pending until it is done. Resolves true when the shortcut succeeds and false when it fails or no shortcut has that name. The shortcut gets no input, and its output is not returned.
See also
- macotron.shell to call
/usr/bin/shortcutsyourself, for example with--input-path. - macotron.launcher for the launcher items in the example.
- The
shortcuts.jsplugin.