I'm attempting to select all text in a thread in InDesign CS4 so I can call another script (not made by me) on the selected text using doScript. This question makes me think it is possible. I tried frame.contents.select();, but this gives the error "frame.contents.select is not a function."
How can I select the contents of a thread in InDesign using extendscript / javascript?
(Any_text_item).contentsis a plain text interface only; it does not directly access InDesign's nativeTextobject, but instead text is translated to and from a regular Javascript string. So selecting the Javascript text (if possible) would do nothing to the text in the InDesign document itself.To get all threaded text from any text frame (or other object), you can use its
parentStoryobject. To select the (native) text, target itstexts[0]property and useselecton that:If you can locate at what point the "current selection" is checked, you can add the following lines immediately before it:1
For example, in the script
markdownId.jsxthat would be near around line 29, just afterยน Best is to test for a property of which you are sure none 'unwanted' objects have. Earlier, I used
parentStorybut realized that a plain text selection also has this property, and so it cannot differ between a regular selection and a text frame. ForpreviousTextFrameyou can be sure that only text frames and text paths are the right kind of object.