Online Book Reader

Home Category

AppleScript_ The Definitive Guide - Matt Neuburg [192]

By Root 1437 0
4.)

Multiple Listings


Sometimes an entry in a dictionary will appear as several different entries, distributed over different suites. For example, in the Finder's dictionary, the application class appears twice, once in the Finder Basics suites, and again in the Legacy suite. This sort of thing probably arises out of decent motives—to categorize different parts of a thing (here, different properies of the same class) by their functionality—but it is utterly maddening for the user. The prospect of having to flip back and forth between two listings of something is unbearable, assuming that one is even aware to start with that there are two listings for it, which is unlikely. If suites are the work of the devil, splitting something over two different suites is punishable in the eighth circle.

Once again, Script Debugger comes to the rescue; if it finds an entry repeated between multiple suites, it collapses them into a single entry in the dictionary display.

Busted Scriptability


Sometimes the reason why you can't figure out how to do something is that it can't be done. For instance, there is no way to close a "dirty" TextEdit document without saving it. (The close command is documented as having a saving parameter to which you can supply a value no, but it doesn't actually work.) And, as we've already seen, you can't get or set the selection in TextEdit. The best approach here is, if at all possible, just to walk away! Don't expect every application to be equally scriptable. TextEdit's scriptability is fundamentally busted, so find some other application that can do what you want to do. (For example, if you need a text processor or word processor, BBEdit , Tex-Edit Plus , and Microsoft Word are wonderfully scriptable.)

Bad Comments


A dictionary is, as I've argued, by the very nature of its underlying format, inadequately informative to users. But everything in a dictionary has a feature that can help compensate for this inadequacy—a comment. A comment is simply a string, so it is a developer's opportunity to say anything at all to the user, in what amounts to a free form, untramelled by the formal restrictions of dictionary structure. A comment is not a perfect medium of communication (it's just a string, it is of limited length, and it can appear only in a restricted set of places in the dictionary), but it is certainly the developer's best chance to make up for the shortcomings of a dictionary entry.

It's surprising, then, that developers fail so often to take advantage of comments. For example, earlier I mentioned that the close command is likely to operate on a restricted set of objects. The comment might be a good place to explain what these are. But here's the Finder's comment on the close command: "Close an object." And here's its comment on the close command's direct object: "The object to close." Thanks for nothing, Finder!

Here's an example of a good comment—the to parameter from the Finder's make command: "When creating an alias file, the original item to create an alias to or when creating a file viewer window, the target of the window." That tells me exactly what this parameter is for; it's used on a limited set of occasions, and the comment says just what they are.

A dictionary with some really splendid comments is Mailsmith's. In a few words it explains how to think about an entry, and even provides examples. Here's how Mailsmith's dictionary describes the text_object class: "Abstract class describing a text object and its basic properties." That is really superb. The dictionary itself has no way to let you know a class is abstract, so the Mailsmith folks come right out and tell you in a comment. And here's what it says about the text_object class's offset property: "Offset of a text object from the beginning of the document (first char has offset 1)." This description actually explains how the characters are numbered! Would that all comments were like these.

Possibly the greatest promise of the new sdef format is that it provides the opportunity for unlimited comments. A comment can

Return Main Page Previous Page Next Page

®Online Book Reader