Sub topic 10
Running shortcuts automatically with automations
This chapter assumes you can build a multi-step shortcut and use Shortcut Input. It also assumes you know how to run a shortcut by hand. Automations build on those skills and add a way to start the shortcut without you.
What an automation is
An automation is a rule that pairs a trigger with a shortcut. When the trigger happens, macOS runs the shortcut. A trigger is an event such as a time of day, a file arriving in a folder, joining a Wi-Fi network, or turning on a Focus.
The available triggers depend on your macOS version. Automations on the Mac are available only in recent releases. Look at the list in your own Shortcuts app instead of relying on this chapter's examples.
Create an automation
- Open the Shortcuts app and choose Automation in the sidebar.
- Click the add button (+) to start a new automation.
- Pick a trigger and fill in its details. For a Time of Day trigger, you choose the time and the days of the week. For a Folder trigger, you choose the folder and whether the trigger fires when items are added or removed.
- Choose what to run. You can select an existing shortcut, or build a new set of actions inline.
- Choose how it runs (see the next section) and save.
Build and test the shortcut by hand first, then attach it to a trigger. A trigger gives you no chance to watch the steps happen.
Choose how it runs
Most triggers let you choose how the automation starts.
| Setting | Behavior | Use it when |
|---|---|---|
| Run Immediately | Starts as soon as the trigger fires, with no prompt | The shortcut is safe and you have tested it |
| Ask Before Running | Shows a notification, and you confirm | The shortcut moves, deletes or sends things |
| Notify When Run | Shows a notification after it starts | You want a record that it ran |
Start with Ask Before Running for any shortcut that changes files. Switch to Run Immediately only after the shortcut has behaved correctly several times.
How the trigger feeds the shortcut
Some triggers carry data. A Folder trigger relates to the files that caused it, so the shortcut can work on those items. A Time of Day trigger carries nothing, so the shortcut must get its own input, for example with a Get Contents of Folder action. Check what the first action receives by running the automation once and inspecting the result, as you did when debugging.
A worked example
Suppose you want files you drop into a folder named Inbox to be sorted automatically.
- Build a shortcut named Sort Inbox that uses Repeat with Each over its input and an If action to check each file's type.
- Run it by hand on a few test files and confirm the results.
- Create a Folder automation for
Inboxthat triggers when items are added. - Select Sort Inbox and set it to Ask Before Running.
- Drop a file into
Inbox, confirm the notification, and check where the file went.
Common errors
- Nothing happens. Check that the automation is enabled in the list. Then check that the trigger really fired. For a Folder trigger, confirm you chose the right folder and the right event (added or removed).
- It runs but fails. The shortcut may expect Shortcut Input that the trigger doesn't supply. Run the shortcut by hand with the same kind of input to reproduce the failure.
- Permission prompts block it. A shortcut that touches files, apps or the network may ask for access the first time. Run it by hand once and approve the prompts, so the automation doesn't stall on them later.
- Runs too often. A trigger such as a folder change can fire again when your own shortcut adds or moves files in the same folder. Write the output to a different folder.
Exercise
You built a shortcut that renames every file it receives, and you attached it to a Folder automation on your Downloads folder with Run Immediately. After a few minutes, it keeps running by itself. What is the likely cause, and how would you fix it?
Show answer
The shortcut renames files in the watched folder, and those changes can trigger the automation again. Fix it by saving the renamed files to a different folder, and switch the run setting to Ask Before Running while you test.