You can execute any of your macOS Shortcuts directly from the command line. This allows for scripting possibilities, enabling you to integrate shell scripts and automations.

Basic Command Structure
shortcuts run "Shortcut Name"
For this to work, you must use the exact name of the shortcut as it appears in the Shortcuts app.

For instance, if the action name is Ask ChatGPT
, It could be like this.
shortcuts run "Ask ChatGPT"
Providing Input to a Shortcut
Standard Input
Many shortcuts are designed to accept various inputs. You can provide the input directly from the command line.
echo "What is the capital of France?" | shortcuts run "Ask ChatGPT"
It only receives input if you set it up like this in a shortcut. You can create this block by entering Shortcut Input

File Input
To provide one or more files as input, use the -i
or --input-path
flag.
shortcuts run "My Image Converter" -i ~/Desktop/abc.png
Saving the Output
If a Shortcut produces an output, You can redirect it to a file using the -o
or --output-path
flag.
shortcuts run "Convert to Lowercase" -i a.txt -o output.txt
You need to add a Stop and Output
block to make it work.

Leave a Reply