Run Shortcuts from the Command Line on Mac
The Mac includes a command line interface to run and interact with Shortcuts app. This could be potentially useful to some macOS users who rely on the Shortcuts app for scripting and automation, and who spend a lot of time in the Terminal
The currently available shortcuts command line flags include ‘run’, ‘list’, ‘view’, and ‘sign’, but note that with the exception of ‘list’, they will all launch the Shortcuts app in the GUI on the Mac.
How to Run Shortcuts from Command Line on Mac
From the Terminal, use the following syntax:
shortcuts run "Shortcut Name"
If the output of the shortcut is text, you can pipe it or redirect into something else via the command line, like more, a text file, or even another app or process.
shortcuts run "Get OSXDaily Recent RSS" | cat
Going further, you can also use the flags –input-path and –output-path to control input and direct output of the shortcuts.
The man page for the shortcuts command is not super complex but it does offer some useful information and is worth a look if you’re interested in understanding the full capabilities of the command line interface to Shortcuts.
List All Available Shortcuts
To get a list of all available shortcuts, use this command:
View the Scripting of Shortcuts
If you want to see the actual scripting of the shortcut, which will launch the Shortcuts app on the Mac, use the following:
shortcuts view "Name of Shortcut"
Currently there is no way to edit or create new shortcuts from the command line, so if you wish to do that, you’ll need to head to the Shortcuts app itself.
If you’re a general fan of automation using the built-in Mac tools, you may also appreciate knowing that you can also run automator scripts from the command line, as well as run AppleScripts from the command line too. And of course all the standard command line scripting features are available through bash, python, perl, etc, if you’d rather go that route.
Do you have an interesting use-case for running Shortcuts via the command line on a Mac? Let us know in the comments!