AppleScript_ The Definitive Guide - Matt Neuburg [261]
One for All and All for One
I now have some idea of how I'm going to refer to an illustration in FrameMaker and how I'm going to mediate between that reference and the pathname of the file on disk that the illustration comes from. So, having solved this piece of the puzzle for one illustration, I move on to the problem of generalizing. I'm going to want to do this for every illustration in the document. How, using AppleScript, am I going to talk about every illustration?
In the previous code, I specified a particular illustration by talking about "anchored frame 22." That's an element specifier, referring to a particular member of the anchored frame class by number. So perhaps the way I'm going to solve the problem is by cycling numerically through the anchored frame elements of my document—that is, by talking about "anchored frame 1," then "anchored frame 2," and so on. I'm a little surprised, to be sure, by how the numbers are working here. I don't have 22 illustrations in this document, so why am I talking about "anchored frame 22"? However, I press on regardless; we'll cross that bridge when we come to it.
Let's see if I can list the inset files for all the illustrations in the document. To do so, I'll start by gathering up a list of all the anchored frame elements; if FrameMaker will let me, I should be able to do it using the word every. Let's try it:
tell application "FrameMaker 7.0"
tell document "gromit:Users:matt2:extra:astdg:ch02"
get every anchored frame
end tell
end tell
Here's the response:
{anchored frame 1 of document "gromit:Users:matt2:extra:astdg:ch02"
of application "FrameMaker 7.0",
anchored frame 2 of document "gromit:Users:matt2:extra:astdg:ch02"
of application "FrameMaker 7.0",
anchored frame 3 of document "gromit:Users:matt2:extra:astdg:ch02"
of application "FrameMaker 7.0",
...
}
And so on. I've left out most of it, but you get the idea. This seems to be working nicely so far. What I've gotten back is a list, and each item of this list is a reference to one of the anchored frames in the document. So I should be able to run through this list and ask each anchored frame for the inset file property of its "inset 1" element, just as I did with anchored frame 22 earlier. I'll start by making a variable allFrames to store the list in, and then I'll see if I can run through it:
tell application "FrameMaker 7.0"
tell document "gromit:Users:matt2:extra:astdg:ch02"
set allFrames to get every anchored frame
repeat with oneFrame in allFrames
end repeat
end tell
end tell
That code runs, which is good. First I've made a variable allFrames to hold the list; then I've made another variable oneFrame to represent each item of that list as I run through it. But the code doesn't do anything, because I haven't said yet what I want to do with oneFrame; there is no code inside the repeat block.
What I'll do now is create yet another variable, allPaths, to hold my file paths. I'll start this variable as an empty list; every time I get a file path, I'll append it to the list. So here's my code:
tell application "FrameMaker 7.0"
tell document "gromit:Users:matt2:extra:astdg:ch02"
set allPaths to {}
set allFrames to get every anchored frame
repeat with oneFrame in allFrames
set end of allPaths to inset file of inset 1 of oneFrame
end repeat
end tell
end tell
I run this code, and—it doesn't work! I get an error message:
FrameMaker 7.0 got an error: Can't get inset file of inset 1 of anchored frame 1
of document "gromit:Users:matt2:extra:astdg:ch02".
I don't really know what this error message means. That sort of thing happens a lot when you're working with AppleScript; stuff goes wrong, but you don't get a very helpful error message explaining why. However, I do see that we didn't get far in the list; right at the start, with anchored frame 1, we had a problem. Now, we know that this is going to work for anchored frame 22, so maybe the problem is related to the mystery of the numbering of the anchored frames. Maybe I've