Online Book Reader

Home Category

AppleScript_ The Definitive Guide - Matt Neuburg [47]

By Root 1452 0
wrapped around that.

Attachability


The most deeply attachable applications I know are the script editor applications Smile and the earlier version of Script Debugger (version 3). For example, Script Debugger implements attachability through a special compiled script file called Attachments. Let's say you edit this file to give it an execute handler. This means that every time Script Debugger is about to perform its own execute functionality, it performs the code in this handler instead. Script Debugger's execute functionality is what it does when it runs a script in one of its script windows. It doesn't matter whether you trigger this functionality by choosing Script → Run, by pressing the Run button in a script window, or by scripting Script Debugger with AppleScript (telling it to "execute" a certain window)—in all of these cases, Script Debugger does what your customizing code tells it to do, rather than what it would normally do. In other words, Script Debugger is factored, and it permits you to customize all the actions that you could normally perform either through the graphical user interface or through the scripting interface.

Now consider an application like BBEdit. Recall (from "Automatic Location" in Chapter 2) that BBEdit has a factored menu implementation: when you choose a menu item in BBEdit, if there is an appropriately named script in BBEdit's Menu Scripts folder, that script is called, so you can customize what happens in response to that menu item. Is BBEdit attachable? Well, it's certainly not as deeply attachable as Script Debugger, because you can't modify what happens when BBEdit receives the "make new text document" Apple event; if BBEdit receives an Apple event, it's going to do what it normally does, and you have no way to customize that. On the other hand, you can modify what happens when a menu item is chosen, so you are certainly customizing how BBEdit responds to an event in its own graphical user interface. So it seems silly to deny BBEdit attachability on the grounds that it is not fully attachable; it merely implements a milder form of attachability than Script Debugger.

Another application that's attachable in a manner similar to BBEdit is Creator , a layout program from MultiAd. It will call a handler in your script when a document is created, opened, closed, saved, or printed, and your script can override the application's default behavior. (Creator is scriptable in other powerful ways as well. You can dynamically add and remove menu items in the menu bar and in the contextual menu, each menu item having its own scripted functionality; and your scripts can even create dialog boxes and other utility windows, with interface widgets that respond interactively through scripts.)

The sign of an application's being truly attachable, I think, is that a user's script can effectively break the application. A simple script given the special name File·Save and placed in BBEdit's Menu Scripts folder can prevent BBEdit from saving files at all. Thus true attachability is dangerous, which is perhaps one reason why it is so rare. The other applications mentioned in "Automatic Location" in Chapter 2 are willing to run your script at a set moment as a way of customizing their overt behavior, but this is not attachability in the classic sense. Apple Mail, for example, will run a script as part of obeying a rule—that is, as a way of answering the question, "How should I respond when a mail message of a certain type arrives?" But mail will still arrive and rules will still be obeyed. What your script is doing here, therefore, amounts to no more than an elaborate way of setting a preference, and doesn't come under the rubric of true attachability. (See also Chapter 26.)

Part II. The AppleScript Language


Part II is the heart of the book; it describes the AppleScript programming language.

This part is intended for use both as a reference and as a source of instruction. The order of exposition is pedagogical, and the chapters are meant to be read in order.

The chapters are:

Chapter 4, Introducing

Return Main Page Previous Page Next Page

®Online Book Reader