AppleScript_ The Definitive Guide - Matt Neuburg [263]
find v : Find text, objects, or properties in a Frame document.
find text/text having paragraph tag/text having character tag/marker/
marker having type/marker containing text/variable/variable having name/
anchored frame/table/table having tag/footnote/xref/xref having format/
unresolved xref/autohyphen : The type of object or property to be found.
[with value string] : The value of the text, tag, type, format, or name
being found.
[with properties list of list] : The properties of the text to be found.
Most text properties will work here. Finding both value and properties
is unlikely to work, and some combinations of properties don't work
well together.
in reference : The document in which to find.
[using use case/whole word/use wildcards/backwards/no wrap/find next] :
The options to be applied to the find.
→ reference : to the object that was found.
The words "anchored frame" in the first paragraph leap right off the screen at me. I can find an anchored frame! I create a new script window in Script Editor, and try it.
tell application "FrameMaker 7.0"
find anchored frame
end tell
No, when I run that it generates an error. What's gone wrong? Oh, I see: I've left out the in parameter. I have to tell FrameMaker what document to look in.
tell application "FrameMaker 7.0"
find anchored frame in document "gromit:Users:matt2:extra:astdg:ch02"
end tell
It works! The first illustration is selected, and the result is a reference to it, just as the dictionary promises:
anchored frame 22 of document "gromit:Users:matt2:extra:astdg:ch02"
of application "FrameMaker 7.0"
So now it begins to look like I can use find repeatedly to get a succession of references to the anchored frames in the document in the order in which they actually appear. To test this idea, I'll just make an artificial loop without worrying for now about how many times I would have to loop in real life:
tell application "FrameMaker 7.0"
set allPaths to {}
repeat 5 times
set oneFrame to find anchored frame ¬
in document "gromit:Users:matt2:extra:astdg:ch02"
set end of allPaths to inset file of inset 1 of oneFrame
end repeat
end tell
allPaths
Here's the result:
{"gromit:Users:matt2:extra:astdg:figs:scriptEditor.eps",
"gromit:Users:matt2:extra:astdg:figs:scriptEditor.eps",
"gromit:Users:matt2:extra:astdg:figs:scriptEditor.eps",
"gromit:Users:matt2:extra:astdg:figs:scriptEditor.eps",
"gromit:Users:matt2:extra:astdg:figs:scriptEditor.eps"}
Oops. We're not moving forward through the document; we're just finding the same illustration repeatedly. In FrameMaker itself, hitting the Find button over and over keeps finding the next match, which is what we want; in AppleScript, though, it appears that giving the find command over and over keeps finding the same match. But wait; the find command has a using parameter where I can specify find next. Let's try that:
tell application "FrameMaker 7.0"
set allPaths to {}
repeat 5 times
set oneFrame to find anchored frame ¬
in document "gromit:Users:matt2:extra:astdg:ch02" using find next
set end of allPaths to inset file of inset 1 of oneFrame
end repeat
end tell
allPaths
Darn it; this generates the same result. I guess "find next" simply means to find forwards as opposed to backwards. The trouble is I'm not finding forwards. It appears that once I've selected something, finding again just finds that same thing again. All right, then, maybe if I can just somehow move the selection point forward a little after finding an illustration, I'll be able to find the next illustration instead of the current one. So now I have to figure out how to move the selection point forward. I start by selecting some text, and then comes a long round of experimentation , of which I'll spare you the details, at the end of which I come up with this:
tell application "FrameMaker 7.0"
select insertion point after selection
end tell
This works just fine when the selection is some text. Unfortunately, as I soon discover, when the selection is an illustration, I get an error