Skip to content

CharacterStyles

app.activeDocument.characterStyles

A collection of CharacterStyle objects.


app.activeDocument.characterStyles.length

The number of characters in the collection.

Number; read-only.


app.activeDocument.characterStyles.parent

The object’s container.

Object; read-only.


app.activeDocument.characterStyles.typename

The class name of the object.

String; read-only.


add(name)

Creates a named character style.

ParameterTypeDescription
nameStringElement name to create

CharacterStyle


getByName(name)

Gets the first element in the collection with the provided name.

ParameterTypeDescription
nameStringName of element to get

CharacterStyle


index(itemKey)

Gets an element from the collection.

ParameterTypeDescription
itemKeyString, NumberString or number key

CharacterStyle


removeAll()

Deletes all elements in this collection.

Nothing.


// Creates 3 text frames in a new document then creates
// a character style and applies it to each text frame.
var docRef = documents.add();
var textRef1 = docRef.textFrames.add();
textRef1.contents = "Scripting is fun!";
textRef1.top = 700;
textRef1.left = 50;
var textRef2 = docRef.textFrames.add();
textRef2.contents = "Scripting is easy!";
textRef2.top = 625;
textRef2.left = 100;
var textRef3 = docRef.textFrames.add();
textRef3.contents = "Everyone should script!";
textRef3.top = 550;
textRef3.left = 150;
redraw();
// Create a new character style
var charStyle = docRef.characterStyles.add("BigRed");
// set character attributes
var charAttr = charStyle.characterAttributes;
charAttr.size = 40;
charAttr.tracking = -50;
charAttr.capitalization = FontCapsOption.ALLCAPS;
var redColor = new RGBColor();
redColor.red = 255;
redColor.green = 0;
redColor.blue = 0;
charAttr.fillColor = redColor;
// apply to each textFrame in the document
charStyle.applyTo(textRef1.textRange);
charStyle.applyTo(textRef2.textRange);
charStyle.applyTo(textRef3.textRange);