 In this video, I'm going to be talking about variables and why you need to know about them if you are going to be using the shortcuts app on Mac OS. Now, this is the third video in a series of videos I'm doing all about shortcuts, a beginner's guide if you will. So be sure to check out those other videos down in the description. But for now, let's get over to the task in hand and variables and let me explain exactly how you can use those in shortcuts. And first of all, exactly what is a variable? Well, a variable is essentially some piece of data that we are going to assign a name to and then use later on in our shortcut to actually form part of the later actions in the shortcut. This will all make perfect sense, I'm sure, as we go through it. So I'm going to start by creating a new shortcut. And again, if you have not used shortcuts before, then be sure to check out the first two videos where I explain all about creating actions and how to use the interface and so on. But for now, I'm just going to click into this new shortcut that I've just created and let's have a look at how we're going to build something out. So a variable, as I say, is essentially a piece of data. It can either be a piece of data that we derive somehow from some other action or it can be something that we actually ask the user for as a form of input. So let's just do something really simple. We're going to have a little alert that pops up on the screen or rather ask a question where we ask somebody for their name and then have an alert that pops up on the screen to say hello to them or something like that. Really simple and pretty much useless example. However, it does serve the purpose of explaining how to use these things. So what I'm going to do is I'm going to come up here and there is a command in shortcuts, which is ask. So if you are asking for some form of input, so I'm going to click on this one and there you see it, ask for input. So I'm going to add that one in. And here we've got a couple of different points that we can adjust. So you'll notice here that it says ask for and then there's this blue text here and then with and then something here. So when you are looking at actions, just bear in mind that anything that is in white is usually some form of description or something like that related to the action itself. And anything in blue is usually something that you can actually adjust or change. Now in this case, the ask for where it says text. This is actually the data type. I'll be covering data types in more detail in the next video. But for the time being, all you need to know is that you can either have it as text or you might be asking for a number. You may be asking for a URL, a date, time or something like that. So these are different types of data that you may be asking for but we're going to keep it simple for the moment and ask for just text. And then here it says with prompt. So we're asking for text with some form of prompt. Now the prompt being what we're going to display to the user so that they understand what it is exactly that we want from them. So how about I just type in here, what is your name? Just like that. Now if I were to run this right now, I mean it's not going to do a huge amount but if I just run that now, you can see that it pops up this little pop-up. This is by the way completely separate from the shortcuts app. It just happens to be over the top of it so that we can see it at the same time. So if I just type in what is your name and I type in my name Alec and then click on done, you can see that that output there has now come into the shortcut and if there were any more actions it could potentially be passed down to anything that happens further down the line. So let's actually do something with that shall we know and let's say that we want to have a little alert box that pops up and just says hi to whoever it is that's typed in their name. So I'm going to look for an alert. So here we go. We've got show alert. It could also have been a little notification that pops out from the side but let's use the alert. And now it's saying show do you want to continue? So we don't want to show something like that. We want to actually just have a response which is to their name. So let me just type in here hi and then I want to actually put, whoops Daisy I need to delete that other, there we go. So now if I was to just run that you can see that what would happen is if I clicked on run, he's going to ask for our name again and click done and then it just says hi. Well that's not very personal isn't it? So wouldn't it be good if we could actually incorporate the person's name into that little structure there? So well we can do that. If I come into where it says hi, I can actually use any bit of data that's already in the action itself from the input. So this essentially is a variable. This is what we're talking about. So if I right click in the alert message and you can see that we've got this option down here to insert variable. Now insert variable, there are different kinds of input that we can put into there but let's just click on this one select variable and this is going to select a magic variable. So there are a couple of different types of variables. There is explicit variables where we're going to give them an actual name and then we can call that wherever we want in the rest of the actions. But magic variables are basically shortcuts built in method where it can actually just pull out certain variables without you having to name them. This isn't necessarily a good practice to get into which we'll come to in a moment but for now let's use this. So you can see that now it is asking me to select a magic variable and the magic variable, the only thing that's magic about it is that it just identifies all the potential variables for you. So here it's saying show alert and we want to add something in there and you can see that we've got this one highlighted provided input. So if I click on that one now what we're going to get is it will say show alert and it's going to say hi provided input explanation mark. What does that mean? Well, it means that whatever they put in here so if I put in Alec and then I click done you can see that now the alert says hi Alec because it has taken the name from there. So why is that not the best way to do it? Well, it's okay for very simple things like that. I mean, that's a very easy straightforward example but what if you wanted to get multiple different bits of data, multiple different variables and then have those feeding in at different points? Well, it can get a little bit confusing when you have lots of these provided input sections here these magic variables. So let me just perhaps give another example of that. So I'll add in a second question. So I'm going to ask two questions now and I'm going to ask, whoopsie daisy, that's the wrong one, I want to ask for input again. So let me say I'm going to say ask for text with a prompt where do you live? And so we're going to have two different variables now. So now I'm going to ask them say hi whatever your name is what's the weather like in wherever you live. So we'll do the same again. I've just added the alert in separately again just so that we can do this from scratch. You'll see what I'm getting at in a moment. So hi, I'm going to put in here, I'm going to say hi and then I want to put their name. What is the weather like in and then we'll put where they live. So here, if I wanted to add in the name I would click in here again as we did before and I would put insert magic variable. So insert variable, select variable and we'll take this one. So we want to add in the name and then we will add in the place where they live in here. So I'm going to do exactly the same. Set variable and we'll take this provided input like that. So now it says hi provided input what is the weather like in provided input. So let's just run this and we'll see what's going to happen. What is your name? Alec click on done, where do you live? Thailand and then click on done and now it's got the output. Hi Alec, what is the weather like in Thailand? So it did work. However, you can see that this may be getting a little bit confusing as you start building out more complex actions or complex shortcuts I should say then using these magic variables where you've got things like provided input, this provided input that is going to get very confusing. How do I know that I've got the right one? How do I know that I'm calling the right thing? Well, it's a lot easier if you actually give these variables all names. So what we could do here is if I wanted underneath here instead of just going straight onto the next section I could actually give this a specific name as a variable. So what I'm going to do is I'm going to use the set variable command. So I'll come to here and search for set variable. There we go. And I'm going to put this one just beneath here and I'm going to, I am going to use the provided input because it's coming straight after this name. So this is the, let's call it username just so that we don't get confused with the actual variable name. So I'm going to call this username. And now let's do exactly the same thing again but for the location and I'm going to call this user location. Okay, so now we have got two variables and what I'm going to do here is I'm just going to delete these magic variables out from here because what we want to do now is we want to add in their name. So what I'm going to do here is go to insert variable and then what I'll do is can you see now what we've got in here is we've actually got this list of variables it actually appears in there. So we can just drag, we can just click on this to add this in directly from this little dropdown. So just once again where that was I'm in this little message that I want to display. I'm going to click right click with the mouse, insert variable and any variables that we have named within this particular shortcut will now appear here. So I'm going to click on username and then if I come to here, what is the weather like? Here we go, insert variable and we'll put user location. You can already see how that is a lot more clear from the point of view of going and doing any editing or things like that at a later date. You can see exactly the inputs that it's taking. So the variable is username and the location is just given there as well. So now if I run that, this will do exactly the same as before with a bit of luck. So I'll type in my name and I'll type in my location and then click on done and there you go. It says exactly the same. Hi Alec, what is the weather like in Thailand? So that is once again a bit of a sort of useless case as a shortcut goes. However, it does demonstrate the way that variables can be used. So let me show you another example now of something that was one that I gave in the first video actually, which was generating a QR code. So I'm going to just come and create a new action but I'll do it from here and I'm going to do it using variables this time. So we've now got generate QR code from URL. Okay, so what we're going to do in here is we are going to basically take a URL from rather than typing it in manually, which is what we did before. By the way, there is a built in generate QR code function or action in here I should say. Now what we did in the first very basic example was we actually just manually typed out the URL in here. But how about you want to be able to copy and paste something from a website or something like that and then actually create the QR code from that. So you're going to take some sort of input. Well, in that case, what you can do is you can use the clipboard, the name escape me there for a moment. So if I type in clipboard, it's going to say get clipboard. And so that is going to get anything that you copy as a URL. It is going to take that information. And now let's actually give that a variable name. There is a bit of a simpler way to do this, but I'm just being very explicit about it so that you can see. So if I go to set variable like this, I'll show you a shortcut to do this. I'm just using this to demonstrate. So let's give this a variable name. Let's call this URL for QR code like that. And that's going to go to copy from the clipboard. And then what I'm going to do is I'm going to then use this QR code function again, generate QR code. And you can see how it has actually already just assumed that we're going to want that. And it's used that it is not the magic variable, though it is the explicit variable. Now what I'm going to do is I'm just going to go to a website. And I'm going to copy, copy the URL. And then I'm going to just come and run this. So now that we've copied a URL, if I run this, it's actually going to create a QR code from that particular URL. And in fact, the URL, if I just output this, I could just delete that and run it again. The output there was actually the take one tech website. Again, take one tech.io slash nothing, just take one tech.io. So there we go. That is how to basically use a URL as the input. I will just show you though, just because that was a bit sneaky. I will just show you how with that particular QR code action like this, you can either do it from text. But what we could also have done is insert variable and we can also just insert directly in there because there is a variable already built in which is clipboard. So we don't actually need to define it like that. Although if you wanted to sort of copy multiple different things and give them all their own explicit variable name, then you could do that. But as I say, you can just actually get clipboard here like this. So that would work exactly the same. If I just run that one, then it has given us the output, the QR code from that particular URL. So that is just a very brief sort of introduction really to variables. And it's intended to just get you understanding the way that you use those and the way that's having explicit variables are named allows you to create sort of a whole batch of different data points or different values or things like that that you can then use at multiple points throughout the rest of your action. Something that will be very important when we get into building out more complex shortcuts. Now the next part I'm going to cover is actually about data types. And I touched on this earlier. So this is going to be coming up right now in the next video over on the right hand side. So I'll see you there.