Online Book Reader

Home Category

AppleScript_ The Definitive Guide - Matt Neuburg [265]

By Root 1511 0
top of the document by selecting the first paragraph. Then I'll cycle through the tables. As I come to each table, I'll get the anchored frame, and from there I'll get the pathname to its source file and append it to a list. I'll continue my policy of cycling some arbitrary number of times, because I don't want to worry yet about the real question of how many times to do it; I just want to prove to myself that I can do it.

The first thing is to learn how to select the first paragraph. This turns out to be somewhat tricky. I try this, but it doesn't work:

tell application "FrameMaker 7.0"

tell document "gromit:Users:matt2:extra:astdg:ch02"

select paragraph 1

end tell

end tell

By once again using my trick of selecting the first paragraph manually and then asking FrameMaker for its selection, so as to learn how it thinks of a paragraph, I finally come up with this:

tell application "FrameMaker 7.0"

tell document "gromit:Users:matt2:extra:astdg:ch02"

select paragraph 1 of text flow 1

end tell

end tell

Now I'm ready to put it all together:

tell application "FrameMaker 7.0"

tell document "gromit:Users:matt2:extra:astdg:ch02"

set allPaths to {}

select paragraph 1 of text flow 1

repeat 5 times

set oneTable to find table 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

A change you'll notice here is the use of the word it. Because the current target is the document, the word it refers to this document. This is needed because the find command requires a reference to a document, but all the other commands are already being addressed to that document.

Here's the result:

{"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"}

That's the right answer: those are the pathnames to the first five illustrations in the document, in the order in which they appear. For the first time since starting to work on the problem, I now believe I'm going to be able to solve it.

Refiner's Fire


Now let's make a few refinements. First, it occurs to me that I'm doing something rather stupid here; I'm finding every table. That's going be troublesome, because some tables are illustrations but some are just ordinary tables. I want to find illustration tables only. I know that in my FrameMaker template these are tables whose tag (or style name) is "Figure." The find command, according to FrameMaker's dictionary, lets me find a table having tag. So that's the way I should find my tables. After a short struggle to understand the syntax of this command, I come up with the following new version of my script:

tell application "FrameMaker 7.0"

tell document "gromit:Users:matt2:extra:astdg:ch02"

set allPaths to {}

select paragraph 1 of text flow 1

repeat 5 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

The result is just the same, so I haven't wrecked the successes I've already had (known in the programming business as a "regression"), and I believe I've eliminated some possible false positives from the find.

Next, let's worry about how to know how many times to loop. By changing "5 times" to "20 times," which is more times than the number of illustrations in the document, and then running the script again, I discover that when I get to the end of the document the search wraps around and starts from the top once more. I try to fix this by adding the option using no wrap to the find, but it doesn't help. Therefore I'd like to know beforehand exactly how many times to loop.

Now, I know from the dictionary that a table has a table tag property.

Return Main Page Previous Page Next Page

®Online Book Reader