Connect apps and files
Run Shortcuts from Terminal
Pass files to a Shortcut with the shortcuts command and capture its output without turning file paths into plain text.
macOS ships a command-line tool that turns every shortcut into something scripts can call. The shortcuts command runs a shortcut by name. When the input is a file rather than text from a pipe, pass it with --input-path.
First, confirm the exact name you’ll call:
shortcuts list
# Prepare Screenshot
# Resize for Blog
Then run the shortcut and tell it where to write its output:
shortcuts run "Prepare Screenshot" \
--input-path "$HOME/Desktop/sample.png" \
--output-path "$HOME/Desktop/output"
Quote names and paths. Shortcut names contain spaces almost by definition. An unquoted name becomes two arguments and a “shortcut not found” error.
Check the result
Check it the way you’d check any command:
echo $?
# 0
ls "$HOME/Desktop/output"
# sample.jpg
A zero exit status means the shortcut finished. A non-zero one means it failed or was cancelled. That’s exactly what a calling script needs to stop a pipeline.
Notice that --output-path only receives something because the shortcut ends with Stop and Output. The contract from the previous lesson is what makes this bridge work. Without it, the folder stays empty and the exit code is still zero.
Hidden interaction
Here is the rule I care about most in this lesson. Design command-line shortcuts with no alerts and no selection dialogs.
When a scheduled script runs the shortcut, nobody is in front of the screen. A dialog does not cause an error. The run just hangs, waiting for a click that never comes. It holds its lock and its schedule slot until you notice, days later.
So every “Ask for Input”, “Choose from List”, or “Show Alert” action is a bug in a shortcut you plan to call from a script. Replace them with input the caller passes in, or with Stop and Respond.
The one-time prompt
Expect a permission prompt the first time your terminal runs a given shortcut. macOS may ask whether to allow it.
Run the command interactively once and approve it. Do this before wiring the shortcut into anything unattended. Otherwise the first scheduled run blocks on a question nobody sees, which is the same hang as above, wearing a different hat.
Try this now with the shortcut you built: run it from Terminal with a test image, check echo $?, and list the output folder. If the folder is empty, go back and check for the missing Stop and Output.
Lesson completed