DekGenius.com
[ Team LiB ] Previous Section Next Section

20.3 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.

Classic implements AppleScript separately from Mac OS X, but the two are compatible and Apple events travel back and forth across the "system barrier." The Classic system contains osaxen, which are implemented by the Classic version of AppleScript. This raises the question of how the presence of osaxen in Classic affects scripts running under Mac OS X.

The answer seems to be that when you run a script under Mac OS X, in code that targets a Classic application, any terminology that is resolved as belonging to a scripting addition is handled by a Classic scripting addition 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:

tell application "Panorama" to display dialog "hello"

The dialog that appears is clearly a Classic dialog. (When I wrote this example, Panorama, my favorite database application, ran only in Classic.)

On my computer, it is impossible to use English-like terminology to call a Classic scripting addition command 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 their way to work.) Fortunately, many commands are defined on both systems. But, for example, this will not compile:

min monitor depth -- compile-time error

and neither will this:

tell application "Panorama"
        min monitor depth -- compile-time error
end tell

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

tell application "Panorama"
        «event aevtgmnd» -- 8 (same as min monitor depth)
end tell

But remember, you have to be targeting a Classic application for this to work. On its own, the same Apple event will fail:

«event aevtgmnd» -- error
    [ Team LiB ] Previous Section Next Section