Section 21.2. Classic Scripting Additions

21.2. 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 (Mac OS 9):SimpleText" tell application f to «event aevtgmnd» -- 8 

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

 «event aevtgmnd» -- error: «script» doesn't understand the «event aevtgmnd» message 

AppleScript. The Definitive Guide
AppleScript: The Definitive Guide, 2nd Edition
ISBN: 0596102119
EAN: 2147483647
Year: 2006
Pages: 267
Authors: Matt Neuburg

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: