I am trying to create a script that will allow me to add words to the document dictionary. I don’t know much about scripting but what I would like to do is:
- If a word is selected return the word
- If some text is selected return the words in the text as an array.
- If no text is selected, but the insertion point is in a word, return the word without any punctuation that might abut it.
A Word in InDesign. as I understand it, is a cluster of characters that does not contain white space or punctuation. The Text Object can be treated as an array of Words. The InsertionPoint is a place within the Word or Text Object? Using app.selection:
If I select a word with the cursor, app.selection.constructor.name returns “Word” and contents returns the word
If I select a word with some punctuation (a comma, for instance) constructor.name returns “Text”, words[0]constructor.name returns “Word” but words[0].contents returns the selected word with the punctuation next to it (but not whitespace).
If no text is selected but the “caret” is in a word, constructor.name returns “Word”, contents returns nothing, but selection.words[0].contents returns the “word” plus punctuation next to it.
What is the connection between words and the Word/Text object in InDesign and how do I extract just the words in the three scenarios listed above?
TIA