Online Book Reader

Home Category

AppleScript_ The Definitive Guide - Matt Neuburg [194]

By Root 1601 0
and deed, the proliferation of scripting additions. The words include official statements such as the following: "There are severe limitations to what you can do in the context of a scripting addition, and the system costs of managing large numbers of scripting additions are high." (The main limitation Apple refers to here is that a scripting addition cannot define any classes. The Apple document I'm quoting also says that scripting additions can't maintain state between calls, but this is no longer true.)

The deeds consist of Apple's own steady retreat from the use of scripting additions, replacing them with scriptable applications (which may be faceless background applications). On Mac OS 9, of the nine files present by default in the Scripting Additions folder, five are applications; under Mac OS X, of the seven files present in /System/Library/ScriptingAdditions, five are applications. (There's no particular reason why such an application should live in the ScriptingAdditions folder; it must still be launched and targeted like any other application. So the placement of these applications in this folder is a way of ensuring their presence while suggesting that they fulfill a utility function similar to a scripting addition.)

Nonetheless, scripting additions have a venerable history and don't show signs of going away anytime soon. In the early days of AppleScript, developers enthusiastically provided freeware or shareware scripting additions, which users have collected with something approaching the fervor with which HyperCard users once collected XCMDs. (A popular and definitive repository of scripting additions is http://www.osaxen.com.) Scripting additions are a convenient way to provide AppleScript with system-level abilities and powers of rapid calculation that it otherwise lacks. They are a fact of life with AppleScript.

Classic Scripting Additions


There is a difference between a scripting addition intended to be used with Mac OS 9 or before and a scripting addition intended to be used with Mac OS X. A Mac OS X-type osax will not work on Mac OS 9. A Mac OS 9-type osax will work on Mac OS X only if it has been Carbonized, meaning that internally its Toolbox calls have been linked against CarbonLib . In general, any particular osax file will probably be intended for one system or the other, not both. You may not be able to tell just by looking; if the Show Package Contents menu item appears in the Finder's contextual menu for an osax, it is certainly for Mac OS X, but otherwise you may need to consult the osax's documentation.

Mac OS X on the one hand, and Classic running under Mac OS X on the other, implement AppleScript separately, but the two are compatible and Apple events travel back and forth between them. This raises the question of how the presence of Classic osaxen affects scripts running under Mac OS X. The answer seems to be that any osax terminology in code that targets a Classic application is handled by a Classic osax if possible. You can see this with a term like display dialog, because the dialogs put up by the Mac OS X and Classic versions of this command differ in appearance. So, for example:

set f to "gromit:Applications (Mac OS 9):SimpleText"

tell application f to display dialog "hello" -- clearly the Classicdisplay dialog

On my computer, it is impossible to use English-like terminology to call a Classic scripting addition command from Mac OS X unless the same terminology is defined by an installed Mac OS X scripting addition. (The Apple documentation claims there's a way to do it with a terms block, but I have not gotten that to work.) So, for example, this works when run in the Classic Script Editor:

min monitor depth -- 8

But this won't even compile in the Mac OS X Script Editor:

set f to "gromit:Applications (Mac OS 9):SimpleText"

tell application f to get min monitor depth

-- compile-time error: Expected end of line, etc. but found identifier

The simplest solution is to employ the raw four-letter code to call the scripting addition command:

set f to "gromit:Applications

Return Main Page Previous Page Next Page

®Online Book Reader