Key Takeaways
- Use the “If” action in Shortcuts to run different sets of instructions, depending on whether one or more criteria has been met.
- You must define the criteria within the shortcut before invoking the “If” action, for example extracting the current weather conditions or your iPhone’s orientation.
- Incorporate multiple “If” actions for to create complex shortcuts that perform different actions based on a whole set of criteria (like two or more weather conditions, or your location and the time of day).
Apple’s Shortcuts app lets you create time-saving workflows and automations, from simple operations to complex multi-step processes. Incorporating the “If” action into your shortcuts can take your workflows to the next level, and give you even more control over your iPhone.
What Is the “If” Action in the Shortcuts App?
The Shortcuts app is full of actions that can perform specific functions on your iPhone. For example, some actions can make calls, some can send messages, some can open apps, and others can change iOS settings. Some actions can get information about your iPhone, such as its orientation, Focus mode, or what music is currently playing.
There are some actions, however, that don’t directly relate to your iPhone at all. These are known as “scripting” actions and their sole purpose is to help you create more complex shortcuts. One of the most useful scripting actions in Shortcuts is the “If” action.
The “If” action is a simple way to get your shortcut to do more than one thing, depending on whether criteria are met. If one thing is true, do this, otherwise, do that.
For example, you can use the “Get Orientation” action to determine which way up your iPhone is. Using the “If” action, you can create a shortcut that follows one set of instructions if your iPhone is face down and a different set of instructions in any other orientation.
Using the “If” action allows you to create shortcuts that can act in two or more different ways, depending on whether the conditions are met. This helps make your shortcuts far more versatile than those that can only perform one set of instructions.
How to Use a Single “If” Action in Shortcuts
The simplest way to use the “If” action in Shortcuts is to use a single instance. This will produce a shortcut that can run two different sets of instructions depending on whether the conditions are met.
In this example, I’ll create a shortcut that checks the current weather. If the weather conditions contain the word “rain” it generates an alert to bring an umbrella, but if they don’t contain “rain” it generates an alert telling you that you don’t need one.
Open the Shortcuts app and tap the “+” (plus) icon in the top right of the screen to create a new shortcut. Tap “Search Actions,” type “Get Current Weather” and select the “Get Current Weather” action.
Now it’s time to add the “If” action that will work its magic in our shortcut. I want the “If” action to check whether the current weather conditions include the word “Rain.”
Tap “Search Actions,” type “If” and select the “If” action. Currently, the “If” action is extracting the date from the current weather conditions, but we want to extract the weather conditions themselves. Tap “Date” and select “Weather Conditions.” Tap “Type” and select “Text.” This will allow the shortcut to search the text for specific text within the weather conditions.
Now I want to determine if the weather conditions contain the word “Rain.” Tap “Is” and select “Contains”. Tap “Anything” and type “Rain.”
The “If” action will look at the current weather conditions and search for the word “Rain.” If it’s found, the shortcut will perform any actions placed beneath the “If” action. If “Rain” isn’t found, the shortcut will instead perform any actions placed under the “Otherwise” action.
Tap “Search Actions,” search for “Show Alert” and select the “Show Alert” action. Select the text and replace it with a message such as “You’ll need an umbrella. The current weather is” and then tap “Weather Conditions” just above the keyboard. This will add the current weather conditions to your alert.
Drag the “Show Alert” action until it is directly beneath the “If” action. This will ensure that this is the alert sent if the weather conditions mention rain. Tap and hold the yellow icon in the top left corner of your “Show Alert” action. Select “Copy.” Tap and hold the icon of the “Otherwise” action and select “Paste Below.”
Tap the text in the action you’ve just copied and edit it to read something like “You won’t need an umbrella. The current weather is, ” leaving the “Weather Conditions” in place. Tap the name of the shortcut at the top of the screen, select “Rename” and give the shortcut a name. Tap “Done” to save it.
The completed shortcut should look something like the image below.
When you run the shortcut, the “If” action will search the current weather conditions for the word “Rain”. If it’s found, the shortcut will display the message about needing an umbrella. If it’s not found, the “Otherwise” section will run instead, displaying the message that you don’t need an umbrella. Two different outcomes from the same shortcut, all powered by the “If” action.
How to Use Multiple “If” Actions in Shortcuts
Using a single “If” action gives your shortcut the ability to run two different sets of instructions; one if the condition is true, and one if it is false. However, you can add additional “If” actions to your shortcut, allowing it to run multiple different sets of instructions depending on multiple conditions. You need to place any new “If” action beneath the previous “Otherwise” actions.
For example, I could add another “If” action to my weather shortcut that would give a third alert if the weather conditions included the word “snow.” Here’s how the shortcut would look with another “If” action added into the mix.
Using “If” Actions With Multiple Conditions
What if, instead of an umbrella, you have a thick raincoat that’s too warm to wear unless it’s really cold outside? You might only want to get an alert when it’s raining, and it’s below a certain temperature.
The “If” action allows you to include multiple conditions that need to be met. You can even choose whether all the conditions must be met for the instructions to be followed, or whether any of the conditions being true is enough. In this final example, I’ll create a quick shortcut that will tell you to wear your thick coat if the weather conditions mention rain, and it’s less than 40F.
Open the Shortcuts app and create a new shortcut. Tap “Search Actions,” type “Get Current Weather” and select the “Get Current Weather” action.
Tap “Search Actions” and add another “If” action. Tap “Date” and select “Weather Conditions.” Tap “Type” and choose “Text.”
Select “Is” and select “Contains.” Tap “Anything” and type “Rain.”
Tap the “+” icon at the end of your “If” action to add a new condition. Tap “Condition” and select “Weather Conditions.” This will get the current weather conditions from the first action again.
Tap “Date” and select “Temperature.” Tap “Is” and select “Is Less Than.” Tap “Number” and type “40.” This creates a condition that the temperature is below 40 degrees.
Search for “Show Alert” and select the “Show Alert” action. Type something like “It’s cold and wet. Wear your big coat.”
The final step is to ensure that both conditions must be met to show the alert. Currently, the message will be sent if any of the conditions are met. If it’s rainy but warm, or dry but cold, the alert will still appear. To ensure that it’s only sent when it’s both rainy and cold, the “If” action needs to be set to “All.”
In the “If” action, tap “Any.” Select “All.” Now the alert will only be displayed if it’s both rainy and below 40 degrees. Otherwise, no action will be taken.
The completed shortcut should look like the image below.
Some Ideas for How to Use the “If” Action in Shortcuts
You can use the “If” action to make some incredibly useful shortcuts. For example, you could create a shortcut that opens Slack when you’re at work or turns your lights on when you’re at home. You should make a shortcut that reads today’s events from your calendar in the morning and reads tomorrow’s events in the evening.
If you’re a fitness buff, you can create a shortcut that plays your workout motivation playlist at the gym but plays your favorite mix at home. You could create a shortcut that brings up your shopping list from the Notes app when you’re near the grocery store but adds items to the list when you’re not. Or you could create a shortcut that opens your podcast app and streams the latest episode of your favorite podcast when your battery is over 30% but brings up an alert reminding you to charge your iPhone if your battery is lower.
You can even create complex shortcuts that take into account a combination of factors such as your location, the time of day, the Focus Mode, and the orientation of your iPhone to make shortcuts that can perform a wide range of different actions.
The Shortcuts app is incredibly powerful and can let you control your iPhone in ways that wouldn’t otherwise be possible. The “If” action is one of the most useful scripting actions, allowing you to make your shortcuts do different things under different conditions. It’s worth playing around with the “If” action in Shortcuts and seeing what you can create.