Online Book Reader

Home Category

AppleScript_ The Definitive Guide - Matt Neuburg [22]

By Root 1377 0

%09get%20name%20of%20every%20disk%0D

end%20tell">click me

A web page is not the only place you can put an applescript link; certain other contexts will permit links that specify non-HTTP protocols. For instance, you can include such a link in a PDF document; this would allow the reader to click in the PDF in order to capture in the Script Editor some code that you have embedded into the link; this device is extensively used in the Take Control electronic book series as a way of letting the reader obtain and run a utility script with no need to copy and paste from the PDF book (see http://www.takecontrolbooks.com). Similarly, you can include such a link in a QuickTime movie (for an example, see http://brennan.young.net/Comp/LiveStage/GenerateASpath.html) and in various other contexts.

Automator


Automator is a utility application, new in Tiger, that allows the user to construct a script (called a workflow ) from a series of steps (called actions) in a graphical interface without knowing a programming language. The default actions are in /System/Library/Automator/; additional actions may be installed into /Library/Automator/ or ~/Library/Automator, or they may be included in an application's bundle, where Automator can see them directly. Workflows can be saved as files to be run by Automator, as applications to be run independently (rather like an AppleScript applet), or as plug-ins for use by various applications: for example, a workflow saved as a Finder plug-in becomes a Finder contextual menu item, and a workflow saved as a Script Menu plug-in becomes a menu item in the Script Menu.

The default actions include a Run AppleScript action , which lets the user incorporate AppleScript code directly into a workflow. Even more interesting, an Automator action can easily be written using AppleScript, and instructions for doing this appear in Chapter 27. An action is a useful way to distribute a piece of AppleScript code to users. You can't know, after all, exactly what a user would like to do with your code, and some users don't understand programming well enough to customize AppleScript code in a script editor themselves. An Automator action can help to solve these problems. An action can easily be positioned among other actions in a workflow that the user constructs in order to achieve a desired result. Furthermore, an action has a graphical interface, which lets the user set various parameters to the AppleScript code without coming into direct contact with that code.

Figure 2-9 shows a simple Automator workflow; it puts up a dialog asking the user to chooose a folder, and lists the pathnames of the items within that folder into a new TextEdit document. Notice the graphical interface that allows the first action to be customized so that the dialog asks for a folder, not a file. Notice also the dataflow paradigm that links the actions: each action produces an output, which functions as the input to the next action in the sequence. The second action produces a list of files and folders (as aliases), but the third action expects text; nevertheless the workflow succeeds because Automator coerces from one type to another as necessary (here, turning a list of aliases into POSIX pathnames separated by return characters).

Automator is in its infancy as of this writing, and it shows. The interface is extraordinarily clumsy: among other things, it's difficult to find the action you want, because the interface, in a misguided attempt to make this easier, causes the order in which

Figure 2-9. An Automator workflow

actions are listed to change constantly (and there's no way to see them simply listed in alphabetical order). There is no provision for branching or looping, so workflows are necessarily very simple. Worst of all, Automator suffers from a serious dearth of useful actions. This, however, is a shortcoming that you, the AppleScript programmer, are in a position to correct. For example, Figure 2-10 shows a workflow that gets the song currently playing in iTunes, retrieves its name, and shows that name as the

Return Main Page Previous Page Next Page

®Online Book Reader