By Jason Snell
December 1, 2021 8:55 AM PT
Run shortcuts from the Mac command line
Note: This story has not been updated since 2021.
I was reminded by Simon Støvring, maker of the excellent Mac and iOS utility Data Jar (which is a persistent data store that’s accessible via Shortcuts), that people may not be aware of just how well integrated Shortcuts is into macOS.
For example, if you’re someone who works in the Terminal a lot, you may not realize that you can integrate Shortcuts (including accessing data from apps like Data Jar) directly into your shell scripts and commands via the
shortcuts command-line app.
I created a small example shortcut called songtitle that outputs the title of the currently playing song.
Now from Terminal, I can use that output in any way you would normally process data. If I want to open the result in BBEdit, for example, I’d type:
shortcuts run songtitle | bbedit
If I wanted to output the result to a file, I can use the
-o flag to direct the output:
shortcuts run songtitle -o ~/songtitle.txt
And if I just want to see the output, I can pipe the result to
shortcuts run songtitle | cat
By the way,
shortcuts will also provide command-line access to the names of all your available shortcuts by typing
And yes, if you’re writing AppleScript scripts, you can use the
do shell script command to gain access to
shortcuts, though the proper way to do this1 is to instead use the new Shortcuts Events helper app:
tell application "Shortcuts Events" set theResult to run shortcut "songtitle" end tell
- In the current macOS Monterey 12.1 beta, no result is returned! Betas. ↩
If you appreciate articles like this one, support us by becoming a Six Colors subscriber. Subscribers get access to an exclusive podcast, members-only stories, and a special community.