AppleScript_ The Definitive Guide - Matt Neuburg [259]
Table A-1. How the O'Reilly illustration department wants figure files named
Fig. No.
Filename
Caption (or description)
1-1
wfi_0101.eps
Overview of the Windows NT operating system environment.
1-2
wfi_0102.eps
Name space presented by the Object Manager.
1-3
wfi_0103.eps
Filter drivers in the driver hierarchy.
2-1
wfi_0201.eps
Local File System.
2-2
wfi_0202.eps
Hierarchical name space for directories and files.
As the example shows, the illustration department would like each illustration file named according to its place in the book. Each name starts with some letters identifying the book, followed by an underscore. Then there are two digits signifying the number of the chapter in which the figure appears. Then there are two more digits signifying the relative position of the figure within the chapter. Finally, there's the suffix indicating what kind of file it is. The illustration department would also like me to attach a list that looks like the table, associating figure numbers, filenames, and captions.
Naturally, as I've been writing the book, I haven't done any of that. It wouldn't have made sense, because I didn't know, as I wrote the book, exactly how many chapters there would be and what order they would be in, and exactly what illustrations there would be and what order they would be in. I've been cutting and pasting and rearranging right up until the last moment. My illustration files simply have whatever names I gave them at the time of creation; these names are generally pretty meaningless, and in the Finder they appear in alphabetical order, which is not at all the order in which they appear in the book. For example, here are the names of the illustration files for Chapter 2, as they appear in the Finder:
automator.eps
automator2.eps
cocoa.eps
fileMaker1.eps
fileMaker2.eps
radio.eps
scriptDebugger.eps
scriptDebuggerDict.eps
scriptEditor.eps
scriptEditorDict.eps
Now, however, the proverbial last moment has arrived. So it's time for me to grapple with the illustration department's requirements. The problem, therefore, is to rename these files in accordance with the chapter in which they appear and their order of appearance within it. Clearly I'm going to have to work in two places at once. In FrameMaker, I need to look at each illustration in order, and see what file on disk it corresponds to. In the Finder, I need to change the name of that file. Then, back in FrameMaker, I need to change the reference for each illustration, so that it points to the correct file under its new name.
This promises to be a massively painful, tedious, and error-prone task—not something I'm looking forward to. Then I get an idea. Adobe FrameMaker is scriptable; in fact, it's extraordinarily scriptable. And so is the Finder. Perhaps this task can be automated using AppleScript.
A Day in the Life
Although I know that FrameMaker is scriptable, I have no idea how to script it. I haven't the slightest notion how to talk to FrameMaker, using AppleScript, about the illustrations in my manuscript. So the first thing I need to do is to try to find this out.
Caught in the Web of Words
My starting place, as with any new AppleScript programming task, is the dictionary of the application I'm going to be talking to, where I examine the terminology I can use in speaking to this application with AppleScript. To see FrameMaker's dictionary, I start up Apple's Script Editor, open the Library window, add FrameMaker to the library, and double-click its icon in the Library window. The dictionary opens, as shown