Join Scott Simpson for an in-depth discussion in this video Introducing AppleScript Editor, part of Learning AppleScript.
The AppleScript Editor application comes with OS X, and it's what I'll be using to demonstrate AppleScript in this course. It lives inside the Applications folder, inside the Utilities folder, under AppleScript Editor. If you're on a Mac with an iCloud account, you might see a different start up window. AppleScript Editor has created a brand new empty file for me. If you don't see one, you can go to File and press New. First, let's take a look at the top portion of the editor window. There's buttons here to control the script. First, there's Record, which let's you record actions that get translated into AppleScript, and I'll go into that in more depth later on.
Next to that are Stop and Run, which we'll use to run a script we write, and if necessary, stop the script before it finishes on it's own. It's nice to be able to stop a script during the development process if you see that something's going to run too long or fail or get stuck. Next to those buttons, there's Compile, which takes the script and translates it into machine code. Again, this is something I'll talk about, in more detail, later on. Over on the right, the Bundle Contents button isn't available right now, but it will be when we build a script bundle. We'll use it to set the name of the application and set some other information.
Below this bar is the script area, where we'll type our AppleScript. I'll put in a quick few lines of code here. So code that I write starts out purple. And when I press Run, the editor reads the script and I get some contextual styling. I'll talk about what that styling means in a movie later on about AppleScript syntax. You'll notice that this text looks a little bit different than in your editor. I changed the font size to make it more readable on my screen. I'll show you how to do that in just a bit. If I right-click here in the code area, I get all kinds of options on the context menu.
There's some common ones, Cut, Copy, Paste, and some font and spelling stuff. There's some handy helpers in here too, in the Substitutions and Transformations menus. And then down at the bottom, there's a bunch of snippets, or stub code. The right common operations for you. In fact, you can see some snippets that look pretty similar to what we'll be writing throughout the course. Down at the bottom of the editor window is the event log, where you can see the results of your script running. This is handy for understanding events and error messages. And you can use the Replies area to see exactly what you get back as your script runs.
Let's take a walk through the items in the top bar. First is the application menu. And the only really interesting thing there is the Preferences option. You can also bring this menu up with Cmd + comma. This is where you can control how parts of the editor look. And here in Formatting is where I change the font size in my editor. It's not terribly evident how to change the values here, so what you do is either select one or more items holding down Cmd for more than one or hit Cmd+A to select them all and then press Cmd+T to bring up the Fonts palette. Then you can set your editor font to whatever you like.
I'm using a larger font that will be more readable on my screen. But you can set yours however you like, or keep it set at the default settings. Then I'll close that, and hit Apply. The other tabs have some other options that you can set to suit your preferences. Over here in the File menu, there's New, which brings up a new script window. And New from Template, which allows you to start a new script with some pre-written code. Some applications can add templates in here, so keep an eye out for that when you install new apps. Open and Open Recent are options you're probably familiar with, but this Open Dictionary option is a handy one that I'll talk about more in the movie about dictionaries.
And then, the rest of the options are pretty standard. Edit and View are pretty straight forward. And the Script menu is another way of getting the commands that have buttons at the top of the editor window. Record, Stop, Run and Compile. Next there is this Font menu up here and it's got all kinds of options, but it's not what I want to use to change the font. If I make a change here it only persists until the application runs. That's not very useful. To make a change that sticks I changed the font in the Preferences menu earlier. Format is pretty standard and Window has some useful options, Event Log History, which shows you a history of the things that have shown up in the event log previously and Library which relates to dictionaries which I mentioned I'll be covering more in depth later on.
Finally, there's the Help menu. The AppleScript Editor help option opens up this handy little box that let's you search through the help topics. It's got a nice list of keyboard shortcuts too. Show AppleScript Help from Help menu gives you a little more information about the editor and the language. But my favorite option here is the Show AppleScript Language Guide. This is a link to Apple's developer documentation where you can find technical definitions and best practices. Throughout the rest of the course I'll be referring to this for information. So, I recommend that you keep it open in a tab. So, I think that's it for now. Let's start taking a look at AppleScript itself.
- What is AppleScript?
- Using comments, variables, text, and numbers
- Working with files and folders
- Using conditionals and creating loops
- Building functions
- Controlling other programs with AppleScript
- Preventing and catching errors
- Distributing your AppleScript application