AppleScript Programming/Basic commands

AppleScript is a programming language that is somewhat similar to English making it easier to understand than some programming languages. The commands in AppleScript are written in a syntax similar to English. This allows users more easily understand the code.

A first script
Alright, let's write our first program! Launch your Script Editor application (in /Applications/Applescript [pre OSX 10.5] or /Applications/Utilities [OSX 10.5 or later]) and type this into your new document:

Then hit the run button.



Your Mac should now play its default beep sound. You have just learned your first AppleScript command:. The above script is the shortest script in AppleScript, or at least the shortest that does something.

Dialog boxes
But if you're going to write a tool for scripting programs or even a small AppleScript program, you're going to need to learn to do more than to make the computer beep. The next command we will explore is " ". A display dialog command is written like this:

This can be used to present information to a user or, as you will find out later, ask for it.

Setting variables
Another vital command you should learn is the " " command. The " " command sets variables to strings, lists, records, and other variable types. Here is a  command in action:

Now, if one wanted to show the user what the text stored in variable "theVariable" was, they could type:

A dialog box would appear with the text "Support Wikibooks!"

Now you know three vital commands and were briefly introduced to strings. More information on strings is in the next module.

Using variables with strings
You can use a variable and a string in the same  line. They are combined with

Exercises
Create a program says "Hello [your name]" with [your name] in a variable.

(Answers)