AppleScript: basic info and syntax
AppleScript is a scripting language that can be used as a kind of "glue" between the system and the Mac applications.
Apple describes it as a tool for repetitive tasks, in fact it a lot more than this: AppleScript is an object oriented language that interacts with all of the objects (and methods) that the system and the applications provide.
Here you will find some basic AppleScript concepts.
This is neither an official guide nor a reference: AppleScript is quite a lot complex and usable for this purpose. Here are only some basic concepts.
In order to start with AppleScript we need to use the Script Editor.
You can launch it on Mac OS X from
“on” - the events (and the comments)
Everything happens in AppleScript is in response to some event.
The most common event is the script’s run, that will look like this:
The handle "run" is invoked when the script starts.
When this handler is onvoked all of the code inside it is executed.
The double hyphen marks a one-line comment, while multi-line comments are marked with
(* ... *)
There are several built-in events, and in addition to those events the user can definre his own events, and pass them parameters:
built-in basic events
Some of the buil-in events used in AppleScript:
Type of data, “set” and “copy”
AppleScript provides some basic type of data built-in in the code:
This introduces the "set" command, that can be used to set the value of some variable to something.
Another way to set the value of a variable is "copy":
The main diffence between the two is that "set" creates a reference, while "copy" copies the value of the expression into the given variable.
In case of simple values (like the ones listed above) the actual effect is exactly the same, while for more complex objects there is a severe difference.