New Programming Model

Learn about the new, easier programming model in Shortcuts.

Transcript

Shortcuts now does a much better job of making programming easy for non-programmers and that's through the new programming model. There's a lot of talk about variables, even in this course. I tried to avoid it, but it's hard not to, because we are making programs here. And variables are just containers, you can put things in them like words or you can put numbers in them. But these are little bits of data that you need as you run your shortcuts.

The problem has always been trying to figure out how to get that variable connected to the specific shortcut step. Siri Shortcuts try to do it for you, but it wasn't really that easy. Ultimately, you needed to use a command called “Get Variable” and even then, you weren't exactly sure when you needed to use it and when you didn't. Even having a lot of experience using Shortcuts, I can tell you quite often, I would run an action that ultimately didn't work because it had the wrong variable.

The Shortcuts team has looked at this problem and came up with a great solution. Actions and shortcuts now display the variable that they're working with. It's no longer a guessing game. And it's now a lot easier.

All right, I've returned to that first Shortcut that I covered earlier in the videos. And this is a simple one. I think it's a good one for looking at this concept of variables, and the new programming model. So in the first step, we have it choosing one photo. And the next step we have sending the latest photo to a group of people. Now that did it automatically because Shortcuts is trying to think for me and-- and make it easy. But if I deleted that, then we'd have the problem that I was talking about earlier in those slides, that you’d say send a message, but you ain't know what the message would be.

The cool thing about the new Shortcuts is it shows you exactly where that missing token is. It says the word message is grayed out. It's telling me “Hey, Dave, I don't know what I'm supposed to send”. By putting it there, it gives me the ability to act on it and make the shortcut complete the first time I build it. I could type in there, if I wanted to. I could just type in there, “Hi Family” and that would be good enough, it would send that out, if I hit the play button in the lower right corner. It's going to grab the first photo and then it's going to create a draft text. Now, it's not using that photo, because I didn't do anything with it. So I'll go ahead and cancel that now. And instead of saying, “Hi Family,” I'm going to delete that.

And if you look at the bottom, now, it's added variables, because I'm on this variable token. I'm going to tap all of it, like I'll tap over here on the names. And then I'll tap and then you'll see it's grey, because there's no variable attached, I'm going to tap on it again, and up comes that variable list in the bottom.

And the first one is the magic variable, the magic wand. I'm going to cover that in the next video. But there's also a bunch of suggestions like I could put the current time in, if I tapped the current time button. Or I could say ask each time, so it would open the message up and then I would be able to type into it. But it's also added this one called latest photos. And that's not normally there. It's here now exclusively, because I have that first step, given the latest photo.

So if I go ahead and tap that, then it's going to grab the latest photo and insert it in the message. So let's run that one now. Got the latest photo, this little image of myself, and it's put it in this text message. But you don't have to just do that, you can get other data as well and put it in there.

I'm going to drag a text field in this time. I'm going to write “Hiya Family” and then down here in the third block the message block, I'm going to tap on the variable again. If you look at the bottom, we got a new button. This one says text and the text is that text box that I just typed. It wasn't there before. But it is now, because I added text.

So if I go ahead and tap that, then it's going to insert that. And if I go ahead and hit the play button in the lower right corner, to test it out, you'll see there it says “Hiya Family,” so you start to get the idea of this is that variables are very easy to declare and find. And more importantly, when you make these actions, you can know exactly what you're adding. Suddenly, the mystery is taken away and everything gets easier.

If I tap on the variable the other way, I can rename it. So I'm going to say Message Text. And now it says Message text, it's turned that block into Message Text. So if I go up and change it. So that was going to grab that new message text and add it to the message. So I'll go ahead and run that. And if I hit the send button here, it will cost me dinner for my whole family.

Once you understand this, you can even start using combined variables in essence, so I'm going to add another block here, may go up here and then select want to have dinner together. I'm going to cut that out, and I'm going to paste it down here. And I'll put an extra space afterwards. And then there's a cool command in shortcuts called combine text. So I'll just type combine, there it is. I’ll add it here. And I'm going to combine these two blocks together. So now I'm taking two separate text blocks and combining them together. But one says text, the other one says new lines. I don't even know really what that is. So we've got to figure it out.

I'm going to tap on the first one and just delete it. And now when I tap on it, you can see that I've got the blocks to choose from, well we know the first one is called Message Text, because we just gave it a name. So I'm gonna say a combine message text.

And then as soon as we did that, we got a little plus button, which is allowing us to add another variable. So I'm going to put that in there. And I've got the exact same option I can choose from a variable. Well, this text below doesn't have a title, we didn't rename it. So I'm going to tap the variable related to that text. And then finally, we can choose is it new lines or is it spaces, we'll go ahead and put New Lines.

Now, finally going down to the fifth block with a message, we just have it pointed at the Message Text. But now we want it to point to the combined text. So I'm going to select the Message Text variable and delete it. And then tap on it again. And you can see down the bottom, there's a block called Combined Text. Well, I bet you know what that's going to do. We'll go ahead and tap that and then run it. There it is a two lines those two separate blocks together. The beauty of this new system is all the mystery is gone. When you look at an action like this sending the message or combining texts, you know exactly what the inputs in and what the outputs are.

I'm not a programmer, I don't want to have to track variables. I want this to be easy. And with this new version and this new programming model, it is. Now let's take this knowledge into the next video all about magic variables.

Complete and Continue