Online Book Reader

Home Category

AppleScript_ The Definitive Guide - Matt Neuburg [11]

By Root 1564 0
this task; iTunes, he said, should include this feature natively. My attitude was just the opposite: thanks to scriptability, iTunes does effectively include this feature natively. "Instead of berating the developers of iTunes for not including that one magic menu item that would do just what you want," I said, "you should be applauding them for making the application scriptable and letting you implement the functionality yourself." Through its scriptability, iTunes is customizable; you can give it features that are within its powers but are missing from its graphical user interface. And this, surely, is the way it should be. If iTunes included a menu item for every task every user on earth would like it to perform, it would have thousands of menu items. Instead, it has a graphical user interface for the tasks that most users want to perform, and leaves the rest up to the individual and AppleScript. iTunes even gives you a way to add your scripts to its graphical interface; put them in ~/Library/iTunes/Scripts/ and they show up automatically in iTunes' Script menu .

Similarly, Microsoft Entourage , an email application, lacks any menu item or keyboard shortcut that truly deletes an email message. Deleting a message that's already in the trash folder (called "Deleted Items") does truly delete it, but deleting any other message merely moves it into the trash folder. This is spectacularly annoying when, for example, you are ready to delete spam messages that have been categorized into the Junk E-Mail folder. But Entourage is scriptable, and it has a Script menu to which you can add your own scripts. So I've written a script to delete all currently selected messages:

tell application "Microsoft Entourage"

display dialog "Really delete selected messages completely?"

set theMessages to current messages

try

delete theMessages

delete theMessages

end try

end tell

Some scriptable applications provide a means for customization at an even deeper level, by letting you modify what happens when you choose one of the application's own menu items or perform some other action in that application. For example, the Finder can be set up with Folder Actions that take over automatically when you do things such as move a file into a certain folder. (See "Automatic Location" in Chapter 2 and "Folder Actions" in Chapter 26.)

Combining Specialties


Different applications are good at different things. Most users don't perform all tasks in a single application. For example, in a word processor, you wouldn't expect to perform extensive editing of pictures: a document might include pictures, but you'd create and edit them in some other program, and then incorporate them into the word processing document. That's how it should be, and that's how users typically like it, especially on Mac OS X where (in contrast to previous systems) there is no significant penalty to running several applications at the same time. "Swiss Army knife" programs that try to be all things to all users generally seem bloated with unnecessary features (such as Microsoft Word, with its Photoshop-like "graphics enhancement" features).

When it comes to assisting applications to combine their separate specialties, AppleScript really shines. Thanks to AppleScript, data can be moved back and forth between applications so that each can operate upon it in the appropriate manner. The result is a workflow in which multiple applications are coordinated, often without the intervention or even the awareness of the user.

Take, for example, SpamSieve . This superb application uses Bayesian algorithms to distinguish between spam and nonspam email messages with astonishing accuracy—far better than those email client programs, such as Entourage and Apple Mail, that include spam filtering of their own. But SpamSieve is not itself an email client. So in order to filter out spam as your email client application receives it, that email client application and SpamSieve must cooperate. The email client receives the mail messages, and hands them over to SpamSieve for evaluation; if SpamSieve

Return Main Page Previous Page Next Page

®Online Book Reader