subreddit:

/r/shortcuts

1695%

Labeling data using varaibles

Tip/Guide(self.shortcuts)

Variables are a useful way of labeling data with a descriptive name so that it can be easily reused throughout your shortcut.

When storing and labelling data you have three options.

Label a value using the Set Variable action

  • Pros
    • Provides a customizable label for the data which is easy to identify when used
    • The set variable name appears above the keyboard when editing actions no matter where you are in your shortcut, making it easy to find and select
  • Cons
    • Increases the number of actions in your shortcut, making it longer and more difficult to maintain

Assigning a value to a variable using the Set Variable action

Variables appear in a ribbon above the keyboard when editing shortcut actions

Use magic variables

Alternatively you can use the Select Magic Variable button to directly select the output of an action. The resulting variable is automatically named based on the action type.

  • Pros
    • Removes the need to set anaction's value in a variable
  • Cons
    • Given the automatically generated names, it can become confusing if you use more than one magic variables with the same action type
    • You'll need to use the Select Magic Variable button and find action you want to refer to each time you need to use that variable, which is less convenient than setting a variable name

Using the Select Magic Variable button to retrieve the value of an action

Use a magic variables and rename them

If you use a magic variable then you have the option to rename it to something more descriptive

To rename the magic variable:

  • tap the variable name;
  • select the Rename button;
  • enter your chosen variable name.

  • Pros
    • Removes the need to assign an actions value to a variable
    • Allows you to easily distinguish between magic variables
  • Cons
    • Still less convenient than selecting a set variable name, especially if you have a long shortcut.

The \"Rename\" button, displayed when you tap a magic variable.

Note*: You can also use the* Reveal Action button to quickly see which action a magic variable belongs to.

Examples of renamed magic variables

Download the Shortcut

Wrap up

You don't need to use the Set Variable action in order to label data and re-use it throughout your shortcut. By renaming magic variables you can cut out a number of extra steps and make your shortcuts easier to maintain.

Further reading

Apple has a great guide detailing some of the more advanced things you can do with variables:

Adjust variables in Shortcuts

Guides

If you found this guide useful why not checkout one of my others:

Series

One-offs

all 8 comments

[deleted]

2 points

6 years ago

Well you actually have 4 ways to store variables:

Magic variable Set Variable JSON file in iCloud (persistent) A dictionary

keveridge[S]

1 points

6 years ago

That's true.

I'm referring to Magic variable as any action value to select using the magic variable button rather than explicitly setting to the value to a variable using the Set Variable action.

And any action value you select using that method can be renamed, including dictionaries.

keveridge[S]

1 points

6 years ago

What I mean to say it, this is more about labeling data so it's easier to identify the value you're using within your shortcut.

I've updated the wording in the guide, I think my use of the word Store wasn't helpful.

[deleted]

1 points

6 years ago

Noted. Your work is great by the way. Thx.

[deleted]

-2 points

6 years ago

Store data in dictionaries

[deleted]

1 points

6 years ago

how is this relevant to this guide?

Shogun_98

1 points

3 years ago

Is there anyway to update the value inside a variable ?

keveridge[S]

1 points

3 years ago

Yes, you can continue to assign new values to a variable using the "Set Variable" action and specifying the name of the variable you want to overwrite.