How to Use Conditional Statements in iOS 12 Shortcuts

Conditional statements in iOS 12 Shortcuts allow you to build dynamic automations that perform different tasks based on specific criteria. By utilizing the built-in "If" scripting action, you can evaluate device states, user inputs, or external data to control the flow of your shortcut. This guide walks you through finding the conditional action, configuring input parameters, and structuring actions within "If" and "Otherwise" blocks for reliable automation.

Understanding the "If" Action Structure

When you add a conditional statement to a shortcut in iOS 12, the app automatically places three connected blocks into your workflow:

  1. If: The entry point where you specify the condition that must be met.
  2. Otherwise: The alternative branch that executes if the condition is not met (equivalent to "Else" in programming).
  3. End If: The closing marker that concludes the conditional check and resumes the standard sequence of actions.

Step-by-Step Guide to Adding Conditional Logic

  1. Open the Shortcuts App: Launch the Shortcuts app on your iOS 12 device and tap the shortcut you want to edit, or tap Create Shortcut to start a new one.
  2. Provide an Input: Conditional blocks require data to evaluate. Add an action that produces output above where you want your condition. Examples include Ask for Input, Get Battery Level, Get Current Wi-Fi Network, or Get Clipboard.
  3. Add the "If" Action:
    • Tap the Search bar at the bottom.
    • Tap the Scripting category (represented by an 'x' icon).
    • Scroll down to the Control Flow section and tap If.
  4. Configure the Condition:
    • Tap the Input parameter inside the "If" block. By default, it usually links to the output of the preceding action (represented by a magic variable).
    • Tap the Condition field. The available comparison options depend on the data type (text, number, or boolean):
      • For Numbers: is greater than, is less than, is, is not.
      • For Text: contains, does not contain, is, begins with, ends with.
    • Enter the comparison value if required.
  5. Add Actions to the Branches:
    • Drag and drop actions directly between the If and Otherwise markers. These actions will only run if the condition evaluates to true.
    • Drag and drop actions between the Otherwise and End If markers to execute tasks when the condition is false.
    • If you do not need anything to happen when the condition is false, leave the space between Otherwise and End If empty.

Example: Low Battery Alert

To see the condition in action, you can build a quick battery check:

  1. Add the Get Battery Level action.
  2. Add the If action directly below it.
  3. Set the condition to: If [Battery Level] [is less than] [20].
  4. Drag a Set Low Power Mode action between the If and Otherwise lines, setting it to "On".
  5. Drag a Show Notification action between Otherwise and End If with the text: "Battery level is sufficient."
  6. Tap the Play button in the top right to test your shortcut.

Nesting Conditional Statements

To evaluate multiple conditions, you can place an "If" block inside an existing "If" or "Otherwise" block. This enables multi-tier logic, such as checking if your device is connected to a specific Wi-Fi network only after verifying that the time of day matches your criteria.