No history yet

Script Editor Basics

Your First Script

Every Mac comes with a powerful, built-in tool for automation called Script Editor and it is the starting point for your journey. It's like a special notebook where you can write instructions for your computer to follow. To get started, you'll need to open it.

You can find Script Editor inside the Utilities folder, which is located in your Applications folder. The quickest way to launch it is by using Spotlight search. Just press Command (⌘) + Spacebar, type "Script Editor", and press Enter.

When you open the application, you're presented with a clean, simple window. This is your workspace. At the top, you'll see a toolbar with a few important buttons. The large, empty area in the middle is where you'll write your instructions, or 'script'. At the bottom, there are a few tabs for seeing the results of your work.

Writing Your First Command

Let's give the computer its first instruction. In the main scripting area, type the following line exactly as you see it:

display dialog "Hello, world!"

This command tells the computer to show a pop-up window, called a dialog box, with the text "Hello, world!" inside it. Now, let's check our work.

Compile, Then Run

In the toolbar, you'll see a button that looks like a hammer. This is the Compile button. Clicking it checks your script for any obvious errors, like typos or incorrect grammar. It's like a spell-checker for your code.

Click the Compile button now. If you typed the command correctly, the text will change color and formatting. This is AppleScript's way of telling you it understands your instructions.

Lesson image

If nothing happens, or if you get an error message, double-check your typing. The most common mistake is forgetting the quotation marks.

Once the script is compiled, it's ready to go. To the right of the Compile button is a triangle icon. This is the Run button. Clicking it executes your instructions.

Click Run. A dialog box should appear on your screen with your message and two buttons, "Cancel" and "OK". You've just made your Mac do something with a script!

Understanding the Results

After you click "OK" or "Cancel" in the dialog box, look at the bottom of the Script Editor window. You'll see a pane that might have been hidden before. This is the feedback area, split into two main sections: Result and Messages.

  • The Result pane shows the direct outcome of the last command that was executed. In this case, it will tell you which button you pressed.
  • The Messages pane provides a log of the entire script's execution, step-by-step. For a simple script like this, it might not show much, but it's invaluable for tracking what happens in more complex scripts.

Think of it this way: Compile checks the recipe for mistakes, Run actually cooks the meal, and Result shows you the finished dish.

This simple workflow—write, compile, run, and check the result—is the fundamental cycle of scripting. You've now completed your first full cycle.

Quiz Questions 1/5

What is the quickest way to launch the Script Editor application?

Quiz Questions 2/5

In Script Editor, what is the primary function of the 'Compile' button, which looks like a hammer?

Now you know your way around the basic tools. In the next section, we'll start giving the computer more interesting instructions.