Skip navigation
frederickyocum
Currently Being Moderated

Finding only the words at a selection point

Aug 8, 2012 9:52 AM

Tags: #script #cs5.5 #javascript #indesign

I am beginning to put together a javascript that will enable me to place words in the document dictionary and am struggling to understand the relationship between InDesign Object Word and the words method and how else I might find only the words within a text object at the selection level.

 

Select "grapes"  run

app.selection.constructor.name returns  "Word"

app.selection.contents returns "grapes"

 

Select "grapes,"

app.selection.constructor.name returns "Text"

app.selection.words[1].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?

 

TIA

 
Replies
  • Currently Being Moderated
    Aug 9, 2012 12:46 AM   in reply to frederickyocum
     
    |
    Mark as:
  • Currently Being Moderated
    Aug 9, 2012 1:01 AM   in reply to frederickyocum

    Sorry I take that back! you can use a grep.

     

     

    mySelection=app.selection[0].words[0];
    myWord=[];
    app.changeGrepPreferences = app.findGrepPreferences = null;
    app.findGrepPreferences.findWhat = "[\\u\\l]+";
    myWord=mySelection.findGrep();
    alert(myWord[0].contents);
    
     
    |
    Mark as:
  • Currently Being Moderated
    Aug 9, 2012 1:04 AM   in reply to Trevorׅ

    Em I fogot you wrote "Short of resorting to regex, is there away to return only the word?"

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 9, 2012 5:50 AM   in reply to frederickyocum

    Pleasure

     

    Don't forget to mark as correct.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 9, 2012 6:08 AM   in reply to Trevorׅ

    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

     

    Trevor

     

    P.s. Thanks for the "Correct" markup

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (1)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points