Online Book Reader

Home Category

AppleScript_ The Definitive Guide - Matt Neuburg [262]

By Root 1395 0
got two kinds of anchored frame: those that represent illustrations and those that don't, which apparently is the same thing as saying those that have an inset file and those that don't.

Because I believe this code should work when I get up to anchored frame 22, I'd like to ignore the problem with anchored frame 1 and any other anchored frames that may not be relevant here. There's an easy way to do this: I'll wrap the code in a try block. I expect I'll still get an error, but now the code won't stop; it will shrug off the error and keep going. In this way I hope to cycle far enough through the list of anchored frames that I get to the ones where I don't get an error. Here's the code now:

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

try

set end of allPaths to inset file of inset 1 of oneFrame

end try

end repeat

end tell

end tell

I run that code, and there's no error. However, I'm not seeing any result! Oh, wait, I understand what I did wrong. I constructed the list, as the variable allPaths, but I forgot to ask for that list as the final result of the script. The result that you see in the Result pane of the Script Editor after you run a script is the value of the last command that was executed. So the way to display as your result the value of a variable you're interested in is to say the name of that variable as the last executable line of your code. Let's try again, like this:

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

try

set end of allPaths to inset file of inset 1 of oneFrame

end try

end repeat

end tell

end tell

allPaths

And here's the result:

{"gromit:Users:matt2:extra:astdg:figs:fileMaker1.eps",

"gromit:Users:matt2:extra:astdg:figs:fileMaker2.eps",

"gromit:Users:matt2:extra:astdg:figs:cocoa.eps",

"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:radio.eps",

"gromit:Users:matt2:extra:astdg:figs:automator.eps",

"gromit:Users:matt2:extra:astdg:figs:automator2.eps",

"", "", "", "", "", "", ""}

Well, that's pretty good. I have no idea what those last seven items are, the ones that just show up as empty strings (symbolized by empty pairs of quotation marks). But in my final code I guess I could just ignore the empty strings, so that's not really a problem. And we've got ten pathnames, which is exactly right because the chapter has ten illustrations.

But there's a problem. A really big problem. The pathnames are in the wrong order.

Remember, our entire purpose is to rename these files in accordance with the order in which they appear in the document. But this is not the order in which they appear in the document. I don't know what order it is, but I do know that the first illustration in the document is scriptEditor.eps. This is a disaster. Our efforts so far have probably not been a total waste, but there's no denying that we're completely stuck. The "every anchored frame" strategy is a failure.

Seek and Ye Shall Find


At this point I'm exhausted and frustrated, so I do something else for a while and brainstorm subconsciously about the problem to see if I can come up with a new angle. Instead of gathering up all anchored frame references as FrameMaker understands them, we want to run forward through the document itself, looking for anchored frames in order, just as a user would. Hmm... as a user would....

This gives me an idea. How would I, as a user, run through the illustrations in a FrameMaker document? I'd use the Find dialog. Perhaps FrameMaker lets me do the same thing with AppleScript. Yes, by golly; looking in the dictionary, I discover there's a find command. Here's the

Return Main Page Previous Page Next Page

®Online Book Reader