Skip to content

Words

app.activeDocument.textFrames[index].words

A collection of words in a text item, where each word is a TextRange object.

The elements are not named; you must access them by index.


app.activeDocument.textFrames[index].words.length

The number of objects in the collection

Number; read-only.


app.activeDocument.textFrames[index].words.parent

The parent of this object.

Object; read-only.


app.activeDocument.textFrames[index].words.typename

The class name of the referenced object.

String; read-only.


app.activeDocument.textFrames[index].words.add(contents[, relativeObject][, inseertLocation])

Adds a word to the current document at the specified location.

If no location is specified, adds it to the containing text frame after the current word selection or insertion point.

ParameterTypeDescription
contentsStringWord to add
relativeObjectTextFrameItem, optionalObject to add item to
insertionLocationElementPlacement, optionalLocation to insert text

TextRange


app.activeDocument.textFrames[index].words.addBefore(contents)

Adds a word before the current word selection or insertion point.

ParameterTypeDescription
contentsStringWord to add

TextRange


app.activeDocument.textFrames[index].words.index(itemKey)

Gets an element from the collection.

ParameterTypeDescription
itemKeyString, NumberString or number key

TextRange


app.activeDocument.textFrames[index].words.removeAll()

Deletes all elements in this collection.

Nothing.


// Counts all words in current document and stores total in numWords
if ( app.documents.length > 0 ) {
var numWords = 0;
for ( i = 0; i < app.activeDocument.textFrames.length; i++) {
numWords += app.activeDocument.textFrames[i].words.length;
}
}
// Creates a new magenta color and applies the color to all words meeting a specific criteria
if (app.documents.length > 0 && app.activeDocument.textFrames.length > 0) {
// Create the color to apply to the words
var wordColor = new RGBColor();
wordColor.red = 255;
wordColor.green = 0;
wordColor.blue = 255;
// Set the value of the word to look for searchWord1 = "the";
var searchWord2 = "The";
var searchWord3 = "THE";
// Iterate through all words in the document
// and color the words that match searchWord
for (var i = 0; i < app.activeDocument.textFrames.length; i++) {
var textArt = activeDocument.textFrames[i];
for (var j = 0; j < textArt.words.length; j++) {
var word = textArt.words[j];
if (word.contents == searchWord1 || word.contents == searchWord2 || word.contents == searchWord3) {
word.filled = true;
word.fillColor = wordColor;
}
}
}
}