Use If actions in Shortcuts
Use the If action (also known as a conditional) to set up a shortcut that checks for certain conditions and operates differently depending on which condition is met. If actions give you the flexibility to set up different paths that your actions can take depending on conditions that are known only when the shortcut runs.
Simply put, the If action lets you express the following in a shortcut: If a condition is true, do this; otherwise, do that. A different series of actions is run for each result.
You can use the If action to test whether content that’s passed into the action as input meets a certain condition. For example, you could use the If action to verify that a web page fetched from a previous action contains the word “meatloaf”.
Note: If you’re unfamiliar with the concept of inputs and outputs, see How do shortcuts work?
Once placed in your shortcut, the If action includes three markers (tags in the shortcut editor): If (not visible as a separate tag), Otherwise and End If.
Within the If marker, you can configure the Input and Value parameters. Tap the Input parameter to choose one of the four available conditions:
Equals: Tests if the input is an exact match to the value you’ve specified, whether text or a number.
Contains: Tests if the input (which may be a body of text or a list), contains text you’ve specified at least once.
Is Greater Than: Tests if the input is greater than a certain number.
Is Less Than: Tests if the input is less than a certain number.
Is Greater Than and is Less Than apply only when a number is passed as input.
Because the If action has two possible outcomes — the condition is true or the condition is false — you can place actions in two paths. When the shortcut runs, a true condition causes the input to be passed to the first action just after If, while a false condition causes the input to be passed into the first action after the Otherwise marker.
The last action to produce output in the If case or Otherwise case passes its content through the End If marker as output (available to retrieve as an “If Results” Magic Variable). This means that the last action in each path of the If action affects the output of the action as a whole.
Tip: You can place If actions within each other to create a more advanced tree of decisions in your shortcut: In the shortcut editor, drag a second If action so that it overlaps the lower portion of the first If action. The second If action is nested (indented) under the first If action.