Text Frames

Some aspects of text frames are relatively easy in scripting. We’ll go into enough of these straightforward properties and methods here so that you can do some useful things with text frames. It’s easier to start with an existing text frame, so start a new document and add a text frame.

Script Label/Name

There’s one scripting property of a text frame that you are probably familiar with in versions before CS5, namely, its label. In the interface you can set that in the Script Label panel (Window → Automation → Script Label). In JavaScript you set it as follows:

app.activeDocument.textFrames[0].label = "test";

You can check in the Script Label panel that the frame has been labeled. Now that the frame has a label, we can refer to it easily using its label or the property itemByname ():

myFrame = app.activeDocument.textFrames.item ("test");
CS3 and CS4

Figure 9. CS3 and CS4

CS5

Figure 10. CS5

myFrame = app.activeDocument.textFrames.itemByName ("test");

Unfortunately, things were changed in CS5 without maintaining compatibility with earlier versions. In CS5 you can still set a label in the interface, but not in a script. And if you labeled a frame in the interface you can’t do anything with it in a script.

Instead, in CS5 you use a frame’s name (new in CS5), which you set in the interface in the Layers ...

Get Scripting InDesign CS3/4 with JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.