Online Book Reader

Home Category

AppleScript_ The Definitive Guide - Matt Neuburg [29]

By Root 1466 0
of the installed component that implements it; you can find out what this is by running the following one-word script in the Script Editor:

version

At the time of this writing, the result is "1.10.3".

Other Scripting Languages


One of Apple's purposes in designing the Open Scripting Architecture was to provide a place for other scripting languages that already existed, and for yet others that might exist in the future—hence the "Open" in its name. AppleScript is the only OSA language supplied by Apple, and in fact is designated the default scripting component, the one that is used when no particular scripting component is specified. Still, in theory there can be others.

In actual fact there have never been many other OSA languages. This may be because developers have not felt much need to supply them. (It also may be because the OSA itself hasn't quite lived up to its original promise.) Here are a few that I know of:

UserTalk , the internal scripting language of UserLand Frontier

QuicKeys Script , the scripting language of CE Software's QuicKeys

JavaScript, by way of Late Night Software's JavaScript OSA

AppleScript Debugger , the debuggable version of AppleScript used by Late Night Software's Script Debugger

The OSABridge components, created by Philip Aker

JavaScript OSA and AppleScript Debugger come in both a Mac OS 9 form (extensions called JavaScript and Script Debugger Nub) and a Mac OS X form (component files called JavaScript and ScriptDebugger). UserTalk and QuicKeys Script were available only on earlier systems. (UserTalk was truly dynamic, being loaded and available to other applications only when Frontier itself was running. On Mac OS X, UserTalk is still Frontier's internal scripting language, but it is not available as an OSA language . Similarly, QuicKeys Script is not present as an OSA language in the Mac OS X version of QuicKeys.)

Let's take JavaScript OSA as an example. (It's free, so you can easily try it out.) You put the JavaScript component file into /Library/Components; you then log out and log in. The effect is that JavaScript is now available as an OSA scripting language on your machine. This means that any OSA-savvy environment can see it. For example, in Apple's Script Editor, there's an OSA language popup menu at the left side of the top of the window, below the toolbar (in Figure 2-1 this says "AppleScript"); this popup menu now displays "JavaScript" as an alternative language, meaning that you can switch to JavaScript and compile and run a JavaScript program, right within Script Editor. This behavior illustrates the dynamic and generalized nature of the Open Scripting Architecture.

(A cool feature of JavaScript OSA is that it adds to the JavaScript language some classes allowing Apple events to be expressed. Thus it enables JavaScript to be used as an alternative to AppleScript for driving scriptable applications. See Appendix B.)

A slightly different approach is taken by the OSABridge components. They do not, of themselves, implement a language; rather, they act as a bridge (hence the name) from the OSA to the text-based shell scripting languages already present in Mac OS X (Perl, Ruby, Python, PHP, sh, and Tcl). Among other things, this bridge makes it easy to package a script in one of these languages as an applet or droplet (see "Applet and Droplet," later in this chapter), and the Tcl component lets your script implement a graphical user interface.

Talking to a Scripting Component


Knowledge of an OSA scripting language resides in the component, not in the OSA-savvy application that uses it. For example, earlier we said, in the Terminal:

% osascript -e 'tell app "Finder" to get disks'

The phrase 'tell app "Finder" to get disks' is an AppleScript expression; when we gave this command in the Terminal, it was obeyed—references to all mounted volumes were displayed in the Terminal. But the Terminal doesn't know AppleScript. The shell, to which we're talking in the Terminal, doesn't know AppleScript. And the osascript program, which we call from

Return Main Page Previous Page Next Page

®Online Book Reader