John Voorhees at MacStories has come up with a clever way to generate a bunch of AppleScript files that just run Shortcuts as a way to open up Shortcuts to apps that support running scripts, but not Shortcuts. Fittingly enough, he uses Shortcuts itself to do the job:
The advantage of using a .scpt file is it can be used by multiple apps. You can drag the file into an ‘Open’ action in the Stream Deck app and run it with the press of a button. Then, you can point Keyboard Maestro at the same file and trigger your shortcut from that app too. It’s a more flexible solution than locking the script in a plug-in.
However, it didn’t take long before building one-off scripts felt like a chore, which is why I created Script Builder. Now, as I go through my library of shortcuts and think about how I can use them on the Mac, I can batch process them into .scpt files.
Should everyone support Shortcuts? Sure. Should Apple make this easier? Probably!
In any event, this is an elegant approach. It occurred to me that a brute-force version of this same approach might also be helpful—basically, a script that could run every few minutes or hours, filling a directory full of AppleScript scripts that simply run whatever shortcuts you’ve got on your Mac, ready to be indexed by LaunchBar and referenced by Keyboard Maestro and Stream Deck and anything else.
Turns out, you can do this as a one-line Terminal command. Here it is:
shortcuts list | xargs -I % sh -c "echo 'tell application \"Shortcuts Events\" to run the shortcut named \"%\"' > '/Users/username/Shortcuts/%.scpt'"
It works—mostly. Shortcuts with a slash character in their name fail, because they’re interpreted as paths. Oh well! There’s always room for tinkering, but I wanted to keep this to a single line. And yes, you need to edit the path to set the output folder correctly, and create that Shortcuts folder.
(Thanks to Greg Knauss for pointing me to the
xargs command that turned this into a one-liner.)
—Linked by Jason Snell