Use variables in Shortcuts
In Shortcuts, you can:
Place a variable in a text field: For example, you can place a variable in the text field of an email shortcut, letting you choose a specific salutation (such as “Dear Sir” or “Dear Madam”) when you run the shortcut.
Pass the contents of a variable as an input to an action: You can manually save the output of any action into a variable and reuse the contents of that variable later in the shortcut. For example, in a shortcut that grabs a book title, you can use a Get Variable action to save the name of the book into a variable. You can then pass the contents of that variable (the book title), into a later action in the shortcut.
Use a variable to replace an action’s parameter (a setting within an action): You can embed a variable in an action. For example, you can place an Ask when Run variable in the Repeat parameter of a Play Music action, letting you choose whether or not to repeat a song when you run the shortcut.
Variables are represented by small, pill-shaped tokens such as or .
Add a variable to a text field
In the Shortcuts app Library , tap on the shortcut you want to modify, then tap any text field in an action.
Note: Not all actions contain text fields.
The Variables bar and keyboard are displayed.
Tap Variables.
The variable bar expands, displaying the Select Magic Variable button and all the manual or Magic Variables made available by previous actions.
Tap Select Magic Variable.
The shortcut editor displays an alternative view showing each action’s output as an available variable, ready for selection.
Tap the variable that you want to add to the text field you selected in step 1.
The variable is placed in-line in the text field (at the original insertion point); this is where the stored data will be placed when the shortcut is run.
You can continue to use the Variables bar to access Magic Variables that you may want to add.
Optional: To add one of the four types of special variables, tap Done, tap a text field, tap Variables, then tap one of the following special variables that appear as green tokens:
Ask when Run: Prompts you to enter text in its place when the shortcut is run.
Clipboard: Inserts what you’ve most recently copied at the time the shortcut runs.
Current Date: Inserts today’s date and time, formatted to your preference.
Shortcut Input: Grabs the input that was passed into the beginning of the shortcut (applicable for shortcuts that are set to the Action Extension type).
Note: On iPhone, you may need to swipe left to see all four special variables.
The special variable is placed in-line in the text field (at the original insertion point).
Remove a variable
In the Shortcuts app Library , tap on the shortcut you want to modify.
Do one of the following:
In a text field: Position the cursor in front of the variable in the text field, then tap in the onscreen keyboard.
In an action’s parameter: Tap the variable token to select it, then tap Clear (to the left of the Rename button).
Pass the contents of a variable as input into another action
In the Shortcuts app Library , tap on the shortcut you want to modify.
Place a Get Variable action above the action that will receive the input, then tap Choose Variable.
In this example, a Magic Variable is available.
Tap Select Magic Variable, then tap a variable in the shortcut editor.
When the shortcut is run, the content of the variable chosen in step 3 is retrieved and passed as input into the action following the Get Variable action.
Replace a parameter with a variable
You can replace an action’s parameter (a setting within an action) with a variable, allowing you to dynamically switch between the settings of an action while a shortcut is running.
In the Shortcuts app Library , tap on the shortcut you want to modify.
In the shortcut editor, tap any parameter name, then choose a replacement variable from the list that appears.
Important: For parameters with on/off switches, use 1 or 0 to set the button as active or inactive, respectively.
In this example, the Ask When Run variable replaces the Repeat parameter in the Play Music action.
When the shortcut runs, you’re prompted to choose a Repeat parameter.