AppleScript_ The Definitive Guide - Matt Neuburg [266]
tell application "FrameMaker 7.0"
tell document "gromit:Users:matt2:extra:astdg:ch02"
tell text flow 1
get tables whose table tag is "Figure"
end tell
end tell
end tell
That works. But I don't really want this entire list; I just want to know how many items it contains. The size of a list can be obtained with the count command:
tell application "FrameMaker 7.0"
tell document "gromit:Users:matt2:extra:astdg:ch02"
tell text flow 1
count (get tables whose table tag is "Figure")
end tell
end tell
end tell
The result is 10. That's correct. So I should be able to use this approach before starting my loop in order to know just how many times to loop. Here's my new version of the script:
tell application "FrameMaker 7.0"
tell document "gromit:Users:matt2:extra:astdg:ch02"
tell text flow 1
set howMany to count (get tables whose table tag is "Figure")
end tell
set allPaths to {}
select paragraph 1 of text flow 1
repeat howMany times
set oneTable to find table having tag with value "Figure" in it
set end of allPaths to inset file of inset 1 ¬
of anchored frame 1 of paragraph 1 of cell 1 of oneTable
select insertion point after selection
end repeat
end tell
end tell
allPaths
And here's the result; it's absolutely perfect, the correct names of the correct illustrations in the correct order:
{"gromit:Users:matt2:extra:astdg:figs:scriptEditor.eps",
"gromit:Users:matt2:extra:astdg:figs:scriptEditorDict.eps",
"gromit:Users:matt2:extra:astdg:figs:scriptDebugger.eps",
"gromit:Users:matt2:extra:astdg:figs:scriptDebuggerDict.eps",
"gromit:Users:matt2:extra:astdg:figs:fileMaker1.eps",
"gromit:Users:matt2:extra:astdg:figs:fileMaker2.eps",
"gromit:Users:matt2:extra:astdg:figs:radio.eps",
"gromit:Users:matt2:extra:astdg:figs:cocoa.eps",
"gromit:Users:matt2:extra:astdg:figs:automator.eps",
"gromit:Users:matt2:extra:astdg:figs:automator2.eps"}
Naming of Parts
Let's now turn our attention to the business of deriving the new name of each illustration. This will involve the chapter number. How can we learn this number?
It happens that in the FrameMaker template I'm using, every chapter document has exactly one paragraph whose tag (paragraph style) is "ChapterLabel," and that the text of this paragraph is the chapter number. So if FrameMaker gives me a way to refer to this paragraph, I should be home free. The dictionary tells me that the paragraph class has a paragraph tag property. Using the same sort of boolean test specifier construct I used a moment ago to find only those tables with a particular table tag, I try to find just those paragraphs that have this particular paragraph tag, expecting there to be just one:
tell application "FrameMaker 7.0"
tell document "gromit:Users:matt2:extra:astdg:ch02"
tell text flow 1
get paragraphs whose paragraph tag is "ChapterLabel"
end tell
end tell
end tell
This doesn't give me an error, but the result is not quite what I expected:
{""}
I guess the problem is that the paragraph itself is empty; the chapter number is generated automatically through FrameMaker's autonumbering feature, and doesn't really count as its text. The dictionary lists a couple of paragraph properties that look promising here:
autoNum string (string) : The automatic numbering format string
paragraph number (string) : The formatted string representation of the
paragraph number
The second one looks like what I'm after, so I try it:
tell application "FrameMaker 7.0"
tell document "gromit:Users:matt2:extra:astdg:ch02"
tell text flow 1
get paragraph number of paragraphs ¬
whose paragraph tag is