Skip to main content
Inspiring
December 23, 2015
Answered

How do I reference the first word of a (threaded) text-frame?

  • December 23, 2015
  • 1 reply
  • 715 views

Hello, there.

I have a series of threaded text-frames.
I want to be able to reference the first word of each one.
[It is no big deal to start project over, and do everything on the fly.]

Any ideas how I could accomplish that?

Any help would be appreciated.

This topic has been closed for replies.
Correct answer Trevor:

Your code works to change the color of the first word. I would like to place the fisrt word in a speerate text frame. When I write "alert(firstWord, "yoo-ree-kah!");" the alert tells me: "[object Word]"


To get the contents of the word use myWord.contents to move the word use myWord.move(LocationOptions.AT_BEGINNING, myDestinationTextFrame);

1 reply

Trevor:
Legend
December 23, 2015

This should help you.

var containers, l, c, firstWords = [], firstWord;

containers = app.selection[0].parentStory.textContainers;

l = containers.length;

for (c = 0; c < l; c++) {

    firstWord = containers.words[0];

    if (firstWord) {

        firstWords.push(firstWord);

        firstWords[firstWords.length - 1].fillColor = app.activeDocument.colors.itemByName("Magenta"); // remove this line if not needed ;-)

    }

}

Trevor:
Legend
December 23, 2015

Or maybe you want

var firstWord = app.selection[0].parentTextFrames[0].words[0];

firstWord && firstWord.fillColor = app.activeDocument.colors.itemByName("Cyan"); // remove this line if not needed ;-)

Inspiring
December 23, 2015

Your code works to change the color of the first word. I would like to place the fisrt word in a speerate text frame. When I write "alert(firstWord, "yoo-ree-kah!");" the alert tells me: "[object Word]"