1. 程式人生 > >Siri Shortcuts: The Best Part of iOS 12

Siri Shortcuts: The Best Part of iOS 12

“turned on iPhone on top of brown wooden surface” by Tyler Lastovich on Unsplash

Siri Shortcuts: The Best Part of iOS 12

Apple released iOS 12 on Monday afternoon. The software update included a number of amazing new features, like Screen Time and Memoji. But the best new feature is found in the App Store:

Shortcuts.

A year ago, Apple acquired Workflow, an app that allowed user-generated automation on iOS. Apple immediately went to work adapting Workflow into what is now Shortcuts.

The app, backed by the power of Siri and integrated into every aspect of iOS, allows users to program Siri to accomplish pretty much anything imaginable. Each shortcut can be defined and set to trigger with custom Siri voice commands. Shortcuts sync across devices through iOS and can be run by any device Siri exists on — iOS devices, CarPlay, HomePod, etc.

I’ve been playing with Shortcuts all week and the app is insanely powerful. There is a robust gallery providing dozens of examples which can be implemented as-is or deconstructed to learn from.

To the right you’ll see the customized shortcut I created for recording my weight in the Health app. I took a very simple example from the gallery and pushed Shortcuts to the limit.

Let’s look at the various steps to learn just what Siri Shortcuts can do:

Section One: Randomized Greeting

The first step in the shortcut begins with a text block. I’ve included a few greetings, one per line. I’ve not discovered a limit to the number of lines you can include.

Following the text block with “Split Text”, set to separate new lines, tells Siri that each line in the text block are individual items. Next is “Get Item” which is set to random. This will pull a random line from the first text block.

The final step in this block, “Set Variable”, does exactly what it says: creates a variable with the random text string pulled from the sample.

In just a few steps, a completely randomized item is selected and set as a variable that can be used at any point throughout the shortcut.

Section Two: Dictate Away

In the second section, I wanted Siri to verbally ask for input, receive verbal input, and convert that verbal input into a text variable.

A simple text block combines the randomized greeting with the main question, “how much do you weigh”. I threw in a sentence requesting only the number since everything I say will be converted to the input variable. If I include “pounds” the Health app won’t know what to do with the information.

Using the “Speak Text” function, one we’ll utilize a few times, Siri takes all of the text from the previous input and says the words out loud. In essence, she asks the question.

Next, I needed to give Siri my answer. I found “Dictate Text” which allows the user to speak to Siri. Combining that with “Get Text From Input” takes what Siri hears and turns it into actual text. So I tell Siri my weight and she converts it to text. It’s then time to define another variable, this time “Weight”.

Section Three: Confirm Dictation

Since Siri occasionally has issues understanding me, I wanted to program in a confirmation block. Using the same “Text” and “Speak Text” combination from before, a simple question and variable call back instructs Siri to make sure she heard the correct weight.

I then found “Show Alert”, which requires user confirmation to proceed. This is the only spot in the entire shortcut where I’m required to physically interact with the device. If Siri heard the weight accurately then I confirm and the shortcut continues. If Siri misheard, I can cancel the shortcut and start it again.

While I’ve dug through a number of functions, I haven’t ruled out the possibility of removing physical interaction. It might require some sort of “If” function, but I haven’t discovered the right combination yet.

Section Four: Log Away

This is the only piece that remains from the original shortcut found in the gallery. “Log Health Sample” takes the input, in this case the weight variable, and inputs the number into the Health app. I followed this step with a “Nothing” command to make sure there isn’t any errant data passed along to the next section.

Section Five: Additional Details

For the final piece, in more of a proof of concept, I wanted Siri to provide me some historical data. In this case, my average weight for the past seven days. I discovered “Find Health Samples Where”, which is extremely customizable. For my purposes, I instructed Siri to pull out weight recordings from the previous seven days.

As before, I converted that input to text to prepare for a calculation. “Calculate Statistics” allows for a number of operations, in this case “Average”. Siri does the math and then defines the number as our final variable.

The only step remaining is for Siri to report the average weight. This step repeats the “Text” / “Speak Text” combination used throughout this shortcut.

Final Thoughts

Did I go overboard? Probably. But while excessive, each step in this shortcut shows the versatility of Siri Shortcuts. In addition to this, I’ve also developed a shortcut to apply watermarks to images and record my daily three questions in Day One.

Have you played with Siri Shortcuts? What have you discovered and created? Let me know with a Response.