Sub topic 2
Actions: the building blocks and how output feeds the next step
This chapter assumes you can open the Shortcuts app on a Mac, create a new shortcut, and add an action to it. You should also know basic Finder concepts such as files and folders. You do not need Terminal yet.
What an action is
An action is one step in a shortcut. Each action does a single job, such as getting text, changing text, or showing a result. A shortcut is a list of actions that run from top to bottom.
Most actions follow the same pattern:
- They take an input.
- They do something with it.
- They produce an output.
How output feeds the next step
By default, the output of one action becomes the input of the action directly below it. You do not have to connect them by hand. The order of the list sets the flow of data.
Here is a worked example you can build now.
- Create a new shortcut and name it "Shout".
- Add the Text action and type
hello macin it. - Add the Change Case action. Set it to UPPERCASE.
- Add the Show Result action.
- Click the Run button (the play triangle) in the toolbar.
A result window shows HELLO MAC. The Text action output hello mac. Change Case received it automatically, changed it, and passed HELLO MAC to Show Result.
Reading an action's parts
Each action in the editor has three parts you should learn to read.
- Title and icon: These name the action, such as Change Case.
- Parameters: These are the fields and pop-up menus inside the action, such as the case style. You set them to control what the action does.
- Input and output: Many actions show a blue input token. You can click it to choose a different source than the action above.
If an action's input token shows the name of an earlier action, the data comes from that action and not from the one directly above it. This matters in the next section.
When the previous output is not what you want
The "output goes to the next action" rule has one catch. Each action replaces the data that was flowing. If you add another action in between, the original output is no longer the "current" data.
Consider this order:
- Text with
hello mac - Get Current Date
- Change Case
Change Case now receives the date, not your text. The Get Current Date action produced new output, and that output moved to the next step. To use the text again, click the input token of Change Case and pick the Text action's output. That output is a magic variable, a named result you can reuse from anywhere below the action that made it. The next chapter covers variables in detail.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| The result is empty or shows "Nothing" | The action above produced no output, or an action in between replaced it | Click the input token and choose the correct earlier output |
| The result is the wrong type, such as a date instead of text | An action between them produced new output | Reorder the actions or select the right input |
| An action shows a warning icon | A required parameter is blank | Fill in the parameter |
| The action cannot run on the data | The content type does not match, such as a file given to a text action | Convert the data first, for example with **Get Text from Input** |
Check your understanding
Exercise
You build this shortcut: Text ("report.txt"), then Get Current Date, then Show Result. The result window shows a date, not "report.txt". Why, and how do you make it show the text?
Show answer
Get Current Date produced new output, and that output became the input of Show Result. To show the text, click the input token of Show Result and choose the output of the Text action. You can also move the Get Current Date action out of the way, or place Show Result directly below the Text action.
Exercise
In the "Shout" example, what do you see if you move Change Case below Show Result, and why?
Show answer
Show Result displays hello mac in lowercase, because it now runs before Change Case. Actions run top to bottom, so the order decides which data each action sees.