AppleScript Tutorial Wiki

This is an AppleScript tutorial. Please use this tutorial as best you can. If you are experiencing difficulties, please discuss them on the Discussion page.

You may also be interested in understanding AppleScript's History.

What do I need to start using AppleScript?[]

AppleScript is a computer language that was designed for use with the Macintosh Operating System, or Mac OS. If you are not using a computer that is running Mac OS, you will not be able to use AppleScript. For more information about Mac OS, check out a fellow wiki on Wikia, the Mac OS X Wiki.

If you have a Mac, you have everything that you need, for now. We will be using Script Editor which, for 10.6 and later, is located in the directory /Applications/Utilities/AppleScript, we will be using AppleScript Editor. Once we get into more advanced programming, you will need the Xcode Tools. This tutorial will tell you how to get them when you need them.

How to use this tutorial[]

At the beginning of each section, an idea for a script will be described. It is suggested that the reader attempts to write the script before viewing the given source code. By doing this, the reader will begin to think like a programmer. This will help when the reader begins to develop his/her own scripts and programs.

Hello World! Script[]

Let's begin with the traditional Hello World! program. Copy and paste the code, found here, into the text area of the Script Editor.

Once the code is in the text area, press the compile button. You will notice that the fonts and colors of the text become varied. This is called pretty-printed. This allows the programmer to noticeably discern certain parts of the code from others.

Once the code is compiled, press the run button. This will run the code. In this example, a dialog box is displayed showing our message of "Hello World!"

See this AppleScript on  for a complete example:

AppleScript Hello World

Copy Cat Script[]

Let's try something a little harder. We are going to make a script that asks for the user to input a word or phrase. The user then clicks enter, and the script displays the text in a dialog box.

Here is the code.

This script gives us our first look at the use of user defined variables in an AppleScript script. In the first line of the code, we set the variable textReturned. This variable is defined by the user, and, therefore, any value can be assigned to it. In this example, a line of text is assigned to the variable.

Say command[]

The say command is something that makes your Mac talk!


say "Babushka"

"Babushka" is what your Mac will say. If you run the script, you will hear a manly voice saying the word blah. If you type something like "ksjhfbkdhsjhdfb", the voice will say it letter by letter.

To change the voice, go to the very top-right corner and click on the magnifying glass. Type in "system preferences" with no speech marks and click on the gear. Click on Speech and you change the stuff.

Tell block[]

The tell command tells an app to do something.

For example:

tell application "Finder" to close every window


tell application "Finder" 

close every window

end tell

The "tell application...." means that the computer tells an app to do something. The part after that is what the app will do. End tell means it will end the tell block and quit.