brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: shortcuts run starts a Mac shortcut from Terminal

Terminal
~/tips/tip-macos-shortcuts-run-terminal

shortcuts run "Combine Images" -i ~/Desktop/*.jpg -o ~/Desktop/combined.png

Runs your Shortcuts app shortcuts from the command line, with files as input.

I like the Shortcuts app on my MacBook, but clicking a shortcut in a menu doesn’t fit in a script. macOS has a shortcuts command for that, and Apple documents it in the Shortcuts user guide.

shortcuts list
shortcuts run "Combine Images" -i ~/Desktop/*.jpg -o ~/Desktop/combined.png

shortcuts list prints every shortcut by name. shortcuts run starts one; put the name in quotes when it has spaces. -i (--input-path) passes files as input, wildcards included, and -o (--output-path) writes the result to a file. Apple’s own example is exactly this one: combine a bunch of JPGs into one picture.

Because the command exits 0 on success and 1 on an error, it fits in shell scripts, cron-style launchd jobs and things like a Git hook. You build the fiddly part (resize, convert, send a message) once in Shortcuts and call it from anywhere.

Caveats: if the shortcut asks for input, the command waits for you, so a script that runs unattended hangs there. Build those shortcuts without questions. And a path you pipe in is treated as text. Use -i when you mean a file.

Further reading: Apple: Run shortcuts from the command line

More Terminal tips ioreg -rn AppleSmartBattery | grep CycleCount Terminal can save your windows and tabs as a window group Export a Terminal profile to a .terminal file and import it on another Mac mc hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000039,"HIDKeyboardModifierMappingDst":0x700000029}]}' All Terminal tips (116) All topics

Link