Mac OS X Unleashed

Mac OS X Unleashed

By John Ray and William C. Ray

Introduction to AppleScript

When creating BSD shell scripts, you are limited to the input and output of the applications being scripted. Complex applications are often impossible to control because of their inability to process standard input. AppleScript works at an entirely different level—within the applications themselves.

To be controlled by AppleScript, an application must implement a scripting dictionary. A scripting dictionary is a collection of commands and functions that can be invoked through AppleScript. Each application determines the features that it makes available for scripting. The result of this approach is that applications can make their most useful functions available through a script, making it possible to create far more complex scripts.

It's also important to note the audience of Mac OS X's AppleScripting capabilities. Shell and Perl scripting are the tools of programmers and system administrators. AppleScript was intended to provide a means for normal, everyday Macintosh users to automate tasks on their computers. The syntax is surprisingly simple and can be understood even if you've never seen a programming language before. For example, take the following code:


   tell application "Finder"
       activate
       close window "Applications"
end tell

It doesn't look like a programming language, but it is. This small example instructs Mac OS X to activate the Finder application, and then close an open window with the title Applications.

Using a language that can almost be read aloud and understood, normal users can write scripts that combine the capabilities of multiple applications.

Share ThisShare This

Informit Network