Previous Page
Next Page

3.7. Applet and Droplet

An applet is an application with very little graphical user interface, consisting essentially of a compiled script along with a minimal amount of standalone executable code, called the bootstrap code, along with some other resources necessary to make the application scriptable. The bootstrap code, which runs when the applet is launched, simply summons a scripting component called the Script Application Component ; this component does the rest, handing the compiled script over to the AppleScript scripting component for execution, and taking care of such application-like functionality as putting up the applet's menu and its description window if there is one. Thus an applet is a tiny application which, when launched, runs a compiled script embedded within it. A script editor application will allow you to make an applet as simply as saving a compiled script file, just by choosing applet format (called "application") when you save (or choose File Save As).

When you save your script as an application, the script editor application looks to see whether it has an open handler. If it does, the application becomes a droplet . A droplet is just like an applet, except that it has a different creator type (the creator type for an applet is 'aplt', while for a droplet it's 'dplt') and a slightly different icon; functionally, the difference is that a droplet does something when file or folder icons are dropped onto its icon in the Finder. Typically, a droplet responds to the dropped items by processing them in some way (for an example, see "Calculation and Repetition" in Chapter 1). A droplet can also function like an applet: as a droplet, it does something when items are dropped onto its icon, while as an applet, it does something when it is launched from the Finder.

An applet's script remains editable unless you save it as run-only . Unlike a compiled script file, you can't edit an applet's script by opening the applet from the Finder, because that launches the applet. Instead, you open it from within a script editor application, using File Open, or by dropping the applet's icon on the script editor application's icon in the Finder. A running applet may also display some graphical interface offering a chance to edit its script.

An applet (or droplet) may alternatively be saved in bundle format; it is then an applet bundle . (Apple's Script Editor calls this format "application bundle.") This format is parallel to a bundle script; it has the same advantages (the bundle can contain other resources) and the same compatibility limitations (it cannot be used on a system earlier than Panther, Mac OS X 10.3). It also has an additional advantage of great importance: an applet bundle can contain and use a scripting addition , thus solving a longstanding limitation of scripting additions; this advantage is shared with AppleScript Studio applications, which are, after all, also a kind of bundle. (See "Scripting Addition" in this chapter, and "Loading Scripting Additions" in Chapter 21. An example of an applet bundle in action appears in "Persistence" in Chapter 27.)

An applet (not an applet bundle) created by Apple's Script Editor can be both executed and edited on any earlier system. Amusingly, this makes an applet a much more portable format than a compiled script file. (An option that was present in earlier versions of the Mac OS X Script Editor, such as version 1.9, to make an applet "require Classic," was confusing and unnecessary and is now mercifully gone. For the same effect, simply use the "Open in the Classic environment" checkbox in an applet's Finder Info window.)

But what about compatibility in the other direction? An applet created in an sufficiently early system obviously can run only in Classic. In (Classic) Script Editor 1.4.3, by which time Mac OS X was already on the rise, there is an option to save as a Mac OS X applet, but in fact the resulting applet won't open in Mac OS X. Finally, in (Classic) Script Editor 1.8.3, this distinction was abolished; an applet saved with this version of Script Editor runs in Classic or in Mac OS X.


For further details about how to make and write applets and droplets, as well as to learn how to use AppleScript Studio to write more sophisticated AppleScript-based applications with a user interface, see Chapter 27.


Previous Page
Next Page