| • Science | • People | • Locations | • Timeline |
The AppleScript project was an outgrowth of the HyperCard project. HyperCard had an English language based scripting language called HyperTalk which could be used for embedding logic and behavior into a HyperCard stack. Apple engineers recognized that a similar type of scripting language could be designed so as to be used with any application, and the AppleScript project was born.
In keeping with the Mac OS tradition of ease-of-use, the AppleScript language is designed on the natural language metaphor, just as the graphical user interface is designed on the desktop metaphor. Thus, the concept of an object hierarchy is expressed using nested prepositional phrases:
pixel 7 of row 3 of TIFF image "my bitmap"which in another programming language might be expressed as sequential function calls:
getTIFF("my bitmap")->getRow(3)->getPixel(7)AppleScript was designed to be primarily used as a scripting language to control other applications. As such, it depends on the Mac OS interapplication communication protocol called AppleEvents, in particular the AppleEvent Object Model. AppleScript uses an application dictionary to associate the AppleEvents with human-readable terms, thus allowing the translation back and forth between human-readable AppleScript and bytecode AppleEvents. To discover what elements of a program are scriptable dictionaries for supported applications may be viewed. Under Xcode or Script Editor click File > Open Dictionary and select the desired application.
To designate which application is meant to be the target of such a message, AppleScript uses a "tell" construct:
tell application "Microsoft Word" to quitAppleScript need not depend on other applications. For very simple tasks, AppleScript can be used for self-contained applets. For instance, the code:
set pix to 72Brings up a dialog box requesting a number of inches from the user. This number is then converted to pixels on a system that uses 72 pixels per inch. A second dialog box is brought up displaying the result.
The problem with this is that, unlike other scripting languages like Perl, AppleScript is very poor in built-in facilities, so such scripts are of limited usefulness and often run quite slowly. The main power of AppleScript derives crucially from its ability to orchestrate the abilities of scriptable applications.
With Mac OS X, AppleScript has grown well beyond its humble beginnings. AppleScript Studio is a development environment which is free with Mac OS X which uses AppleScript as the primary programming language, in conjunction with the Cocoa-based ProjectBuilder framework used to construct graphical user interfaces.
With Mac OS X 10.3 (aka Panther) AppleScript Studio and ProjectBuilder have been rolled into the XCode integrated development environment. AppleScript Studio lets you build a User Interface in a drag and drop fashion (similar to Visual Basic) and then 'run' the User Interface to see what the forms and menus looks like.
Panther also comes with Script Editor , which is a minimalist editor for compiling and running AppleScripts. A nice feature of this editor is that if you right click (command click) on the editing area you get a pop up menu with a large range of options for script fragments to paste into your code. This is an excellent feature for people learning to write AppleScript. From that menu you can also open up the directory where these scripts are kept, and have a look at them. You can also add your own Scripts (though you need to restart Script Editor for these changes to show up in the pop up menu. Using these features, you can turn Script Editor into a minimalist, but extensible, Java IDE for example.