InDesign’s Object Model
The object model is best explored in the ESTK, so fire it up and press Ctrl/Cmd+N to start a new script file. Make sure that the console is displayed. In InDesign, start a new document, create a text frame, and fill it with placeholder text. Place the cursor somewhere in the text.
In the ESTK, place the cursor in the blank script window, type
app.selection[0]
and run this one line
(press F5 or choose Run from the Debug menu). ([0]
is an index; its meaning is not very
important just now.) This one-line script tells you what is selected in
the InDesign document. In the JavaScript console, ESTK reports [object InsertionPoint]
.
This tells us that what we have currently selected is an object of
type “insertion point.” (This is sometimes also referred to as “the cursor
position.”) Let’s experiment a bit further. Go to the InDesign document
and select just one character. Return to the ESTK and choose Run again.
ESTK now reports [object Character]
.
Let’s try some more: in the InDesign document, select a word by
double-clicking it; ESTK tells you that your selection is a word object:
[object Word]
. Go on to triple-click
somewhere in the InDesign document to select a line, and run the script
against that selection: [object Line]
.
Quadruple-click somewhere in a paragraph, and ESTK says [object Paragraph]
. Finally, select the whole
text frame in InDesign (Ctrl/Cmd+click) and choose Run in the ESTK; it
reports [object TextFrame]
. So you see, whatever you have selected, ...
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.