Select "grapes" run
app.selection.constructor.name returns "Word"
app.selection.contents returns "grapes"
app.selection.constructor.name returns "Text"
app.selection.words.contents returns "grapes," not grapes.
Any punctuation that is attached to a word in a selection other than whitespace appears to be considered to be part of the word in the words collection.
Short of resorting to regex, is there away to return only the word?
Sorry I take that back! you can use a grep.
mySelection=app.selection.words; myWord=; app.changeGrepPreferences = app.findGrepPreferences = null; app.findGrepPreferences.findWhat = "[\\u\\l]+"; myWord=mySelection.findGrep(); alert(myWord.contents);
Many thanks the link explained what I thought was happening. I was going to explore grep, but thought I might be missing something and there was some DOM element I had missed. Thanks also for the script snippet you have done my work for me!
InDesign must do some sort of grep internally because if you highlight a word plus punctuation and attempt to add it to the dictionary, it strips off the punctuation.
Just a little correction to the Grep
It should probably be
app.findGrepPreferences.findWhat = "[\\u\\l']+";
with the ' apostrophe added to the character class so you get grape's
P.s. Thanks for the "Correct" markup