iOS Shortcuts — Automating your Workflow

iOS 12 brought us the Shortcuts app, which was previously known as Workflow until Apple bought the application. Essentially, Shortcuts allows us to automate various aspects of our workflows or repetitive tasks. There are some limitations, which I will come back to later in this article.

The Shortcuts app is almost no-code, meaning you don’t write program code to perform the work. I say almost because you still have to design the logic flow and perform some elements of programming including variable assignments, flow control, etc. However, the drag and drop approach makes design and implementation pretty easy.

Shortcuts are small programs allowing you to perform repeated tasks ranging from simple to very complex workflows. The scripting language supports flow control, interactions with various components in iOS, and even applications that provide support to access application features from Shortcuts.

Actions represent a single step in the workflow. For example, this image shows three actions:

  • retrieving all of the keys from a dictionary;
  • asking the user to select a value from the retrieved keys;
  • set the value of a variable with the chosen item.
Three Sample Actions
Three Sample Actions

If you are not familiar with a dictionary, it is a key-value store, where the key is the name of the object and its associated value.

Shortcuts groups available actions into several categories:

  • Apps; lists all of the apps on your iOS device which have support for Shortcuts;
  • Scripting; contains flow control, input, and more actions to control the flow of your Shortcut;
  • Location; actions to get your device locations, find routes or locations with maps, and other actions where your drive location is needed;
  • Sharing; as the name implies, actions to share information with other people, apps like Facebook, Twitter, etc., or actions to share using AirDrop or iCloud;
  • Favorites; actions you have indicated are favorites, which saves looking for them in the other sections;
  • Media; for interacting with and controlling music, photos, sounds, App Store, camera, etc.;
  • Documents; contains actions for interacting with document apps like Notes, Bear, the Files app, PDF, and other text-based actions; and,
  • Web; with actions for interacting with data that is on a network either through a web browser type connection or other services.

Clicking on any of the groups shows the actions available in that group.

Automations are shortcuts triggered by an event rather than manually through the Shortcuts interface or widget. Personal Automations are those executed on your iPhone or iPad, while a Home Automation is available to everyone in the home. For example, here is an example home automation that turns on the light over our kitchen sink at 6:00 AM each morning.

A Home automation to turn on a light
A Home automation to turn on a light

This article, however, is going to look at building a complex, multi-action shortcut.

To illustrate how to build a shortcut, I am going to walk through one which I created to help my wife and I on our farm figure out when an animal may be due to deliver their young, or when breeding occurred. The flow is this:

  1. Do we want to estimate a breeding date or a delivery date?
  2. For what animal?
  3. Enter the date when breeding or delivery occurred.
  4. Do the date calculation.
  5. Print the result.

Sounds pretty simple, but building it in Shortcuts is different from a programming language like Python, Go, or Swift. Let’s see how by working through this example.

The first thing the shortcut does is prompt the user to choose between estimating breeding or delivery date.

Selecting what we want to estimate
Selecting what we want to estimate

This uses a list action to display the two options and allow the user to select one or the other. The scripting block following the list definition causes a prompt and the list values to be displayed to the user.

Once the user has made a selection, we assign the ChosenItem to the variable dateType, which we will use in several flow control actions during the script.

We then use an If block to test what the user just selected and assign another variable with the opposite value. This is used purely for displaying more meaningful text to the user.

Saving the selection
Saving the selection

One would think we should just be able to assign a text value to the variable using the set variable action. However, this action cannot accept a text string as input. Rather, we have to define the text and then use the Text as the input to set variable.

Next, we define the dictionary containing the list of animals and their average gestation periods, and then we get a list of all of the keys in the dictionary.

Creating the Animal Gestation Period Dictionary
Creating the Animal Gestation Period Dictionary

Remember, a key is how we look up something in the dictionary to get its value. We retrieve all of the keys so we can build a list of animals the user can select from.

Getting the selected animal from the user
Getting the selected animal from the user

Again, we get the list of dictionary keys, which are the names of the animals, and we ask the user to choose from the list. Once they have made a choice, we save the selection in a variable called Animal.

Retrieve the selected animal's gestation period from the dictionary
Retrieve the selected animal’s gestation period from the dictionary

Using the Animal variable, we get the average gestation period from the dictionary and save the value to the variable Period.

The next step is to determine when breeding occurred (we are estimating a delivery date) or when the baby animals were born (we are estimating a breeding date). This is done by creating a prompt using a Text action, and then using a menu the user selects from with the prompt for the menu the newly created Text value.

Getting the date from the user
Getting the date from the user

Menus are interesting in Shortcuts because it provides an execution path for each of the menu options. If you have distinct actions to take for each choice, then build those actions into the appropriate section.

The Menu execution path
The Menu execution path

Selecting the Current Date option, causes the action to use the Current Date value, while selecting Enter a Specific Date causes the black to collect that date from the user is executed.

Calculating the Result
Calculating the Result

We then format the date and evaluate if we are estimating Breeding Date or Delivery Date. If we are estimating Breeding Date, we have to subtract the number of days for the average gestation period from the date provides by the user, and if estimating the delivery date, we add the number of days.

We are almost to the end of the Shortcut.

Preparing the Result
Preparing the Result

We format the newly calculated date and again based upon what we are estimating, we prepare the text we are going to display to the user, and then display it.

Showing the Result
Showing the Result

That’s it. Our shortcut is complete. It can be available on your iPad, iPhone, and even Apple Watch.

Here are some screenshots illustrating the shortcut result on an iPad and an Apple Watch.

Showing the Result on an iPad
Showing the Result on an iPad
Showing the Result on an Apple Watch
Showing the Result on an Apple Watch

While you can accomplish a lot with just the scripting language and some functionality provided by the native Apple apps, many App Store applications also provide Shortcut actions you can use in your shortcut. However, many of your favorite applications may not provide any or only a few shortcuts.

Shortcut enabled Apps
Shortcut enabled Apps

My iPad says I have 143 applications installed, yet only 46 of them are in the Apps list within Shortcuts. If you want to create a shortcut using an application that is not on the list, reach out to the app developer and ask them to include support for Shortcuts in their application.

If you want to use the shortcut discussed in this article, you can get it at Animal Gestation Calculator.

Another sample Shortcut which creates a card in a selected Trello Board and list is available at iCloud Trello Card Shortcut.

Shortcuts can be used to automate tasks you perform frequently, so you don’t have to manually perform all of the steps. For example, I have a “Resize Photo Width” shortcut where I specify the desired width, choose the photos, and the shortcut resizes the images whether there is 1 or 1,000.

Shortcuts User Guide

Chris is a highly-skilled Information Technology, AWS Cloud, Training and Security Professional bringing cloud, security, training, and process engineering leadership to simplify and deliver high-quality products. He is the co-author of seven books and author of more than 70 articles and book chapters in technical, management, and information security publications. His extensive technology, information security, and training experience make him a key resource who can help companies through technical challenges. Chris is a member of the AWS Community Builder Program.

This article is Copyright © 2020, Chris Hare.

Written by

Chris is the co-author of seven books and author of more than 70 articles and book chapters in technical, management, and information security publications.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store