Run shortcuts from the command line
You can use the Terminal app on your Mac to run a shortcut from the command line. Running shortcuts from the command line is no different from running shortcuts in the Shortcuts app—you can pass documents, images, text, and more. Then the shortcut can pass the output to another process or write to a file.
Although you can run nearly any shortcut from the command line, the most efficient shortcuts are ones that don’t show alerts or ask for input. When a shortcut asks for input, the command line process pauses, awaiting user input. Instead of using a Select action, configure your shortcut to receive specific content as input, and if no input is received ask the for the content. See Limit the input for a shortcut when run from another app on Mac. Allowing images to be passed to the shortcut and asking if they are absent allows a single shortcut to be run from anywhere, prompting the user only when necessary.
Running shortcuts from the command line
Shortcuts are run using the
shortcuts command. To run a shortcut named “Combine Images” you need to account for the space using one of the following:
shortcuts run "Combine Images" or
shortcuts run Combine\ Images
You can pass images to shortcut using the
--input-path flag. You can pass image paths with space-delimited absolute or relative paths, or using wildcards. To run the “Combine Images” shortcut and pass all JPEG files on the Desktop, you could use the following:
shortcuts run "Combine Images" -i ~/Desktop/*.jpg
Note: When you pass a file path using a pipe (
|), the path is treated as text. Use the
-i flag to ensure your input is treated as file paths.
If your shortcut ends with an action that produces text, images, or some other file, or if you use the Stop and Output action, you can add the
--output-path flag to intelligently write the output to a file. For example, you could output text to a PDF or TXT file by providing a path with the proper file extension. To run the “Combine Images” shortcut combining all the images on the Desktop to a PNG file, you could use the following:
shortcuts run "Combine Images" -i ~/Desktop/*.jpg -o ~/Desktop/combined.png
If the shortcut has an action that ends with output or has a Stop and Output action, you can pipe the output of a shortcut to another command using the
| character. You can define the type of output (for example, forcing the output to be a JPEG instead of text) by using the
--output-type flag with a Uniform Type Indicator. To run the “Combine Images” shortcut combining all the images on the Desktop and passing to another command as an RTFD, you could use the following:
shortcuts run "Combine Images" -i ~/Desktop/*.jpg --output-type com.apple.rtfd | …
For a list of Uniform Type Indicators see System-Declared Uniform Type Identifiers.
shortcuts command will exit
0 on a successful run or
1 on error.
Listing shortcuts on the command line
You may want to check that a shortcut exists before running other automation or see a list of shortcuts when the GUI is not available. You can list all the shortcuts available using
shortcuts list. You can also list shortcuts in custom folders. Use the
-f flag and provide a custom folder name. For example, if you want to list all the shortcuts in your custom folder with the name “Music,” use the following:
shortcuts list -f Music
Note: You can only use the
-f flag with custom folders, you cannot use generated folders such as “Quick Actions,” “Menu Bar,” and so on.
To list all your folders instead of the shortcuts, you can use the following:
shortcuts list --folders
Viewing shortcuts from the command line
You can open a shortcut in the editor using
shortcuts view. This can be helpful in troubleshooting an errant shortcut. To view a shortcut named “Bad shortcut,” use the following:
shortcuts view "Bad shortcut"
Signing shortcuts from the command line
You can sign a shortcut that you previously exported using
shortcuts sign. When you sign a shortcut, Apple receives a copy for validation (to prevent unauthorized tampering when you share it). Shortcut signing has two modes:
Anyone: Anyone can import your shortcut.
People who know me: Only people who have you in their contacts will be able to import your shortcut. Your contact info will be included in the shortcut file.
To sign a shortcut named “Share me,” use the following:
shortcuts sign --mode people-who-know-me --input "Share me.shortcut" --output "Share me signed.shortcut"
For information on sharing shortcuts, see Share shortcuts on Mac.
Though you can use x-callback-urls to run and view shortcuts from the command line, you should use the
shortcuts command to be able to provide intelligent input and output. See Intro to URL schemes in Shortcuts on Mac.