An Intro to AppleScript

Although it has been available for over a year, AppleScript is something of a dark horse among system software extensions. Being neither as useful as WorldScript or as much fun as PlainTalk or QuickTime, it does not generate the same interest or enthusiasm among Mac Users. This has also not been helped by AppleÕs policy on distribution. There are a number of ways to get AppleScript, i.e. on its own, with System 7 Pro, or with HyperCard 2.2. But all of these cost money, and for most Mac users they are not exactly compelling purchases.

As importantly the support for AppleScript in the Mac system has been virtually non-existent, limiting the appeal of AppleScript unless users have other applications thay can use it with. But not for much longer. The imminent release of System 7.5, likely to be a very attractive upgrade for most Mac users, should include AppleScript together with a new Finder which works with it.

With this putting a more useful version of AppleScript into the hands of a lot more Mac users, we can expect to see it take off in the next twelve months, as more and more users learn the benefits of using it and more and more developers include it in their applications.

But what is it ?

AppleScript is a powerful, sophisticated programming language for the Mac, flexible enough to work with a variety of applications and extensions, but simple enough to be easily understood by even people with no previous programming experience. Too good to be true ? Read on and see for yourself.

AppleScript's power and flexibilty comes from the applications it can work with. Using simple English-like constructs AppleScript can 'tell' applications what to do. You should be able to work out for yourself what the following do:

tell application "Finder"
    empty trash
end tell

tell application "FileMaker Pro"
    Duplicate Record 1
end tell

tell application "StuffIt Expander"
    Expand "archive.sit"
end tell
The power of AppleScript comes from combinations of commands for more than one application. For example the following commands:
tell application "StuffIt Expander"
    Expand "archive.sit"
end tell
tell application "Finder"
    move "archive.sit" to the trash
    empty trash
end tell
will decompress and delete a compressed archive, using the same programs that you might use to do the job yourself. The formatting of the commands is part of AppleScript, which automatically formats a script when AppleScript checks it before saving or running it, making AppleScript very easy to read and work with.

Applets, Droplets and OSAXs ???

The other part of AppleScriptÕs flexibility is in Scripting Additions (OSAX): these are small extensions to AppleScript, placed in the Scripting Additions folder in the Extensions folder to add one or more commands to AppleScript itself. For example both of the following commands:
set depth of monitor 1 to 8
say "Hello There !"
work by using such Additions.

An Applet or Script Application is a Script hidden in an application: run the application and it runs the commands in the script. A Droplet is a script application onto which you drop files, folders or disks for it the script application to work on. These are typically very small programs, only around 5-10k in size, small enough that you can create a number of them, each to do a seperate task, without taking up much disk space.

Perhaps the quickest way to learn about AppleScript is to look at examples of scripts created by other people. Some come with AppleScript, and more can be found on the HKMUG BBS and other online services [follow this link to one of my own]. If you are seriously interested in AppleScript Apple have produced a small but comprehensive language guide, which can be picked up in most good computer bookstores.

This article first appeared in the September 1994 edition of the Hong Kong Mac User Group newsletter.

© John Blackburne, johnb@hk.super.net, 17th March 1996


up to John's Home Page