Skip to content

Swatch

app.activeDocument.swatches[index]

A color swatch definition contained in a document. The swatches correspond to the swatch palette in the Illustrator user interface.

A script can create a new swatch.

The swatch can hold all types of color data, such as pattern, gradient, CMYK, RGB, gray, and spot.


app.activeDocument.swatches[index].color

The color information for this swatch.

Color


app.activeDocument.swatches[index].name

The swatch’s name.

String.


app.activeDocument.swatches[index].parent

The object that contains this swatch.

Document; read-only.


app.activeDocument.swatches[index].typename

The class name of the object.

String; read-only.


app.activeDocument.swatches[index].remove()

Deletes this object.

Nothing.


// Changes the name of the last swatch
if ( app.documents.length > 0 && app.activeDocument.swatches.length > 0 ) {
var lastIndex = app.activeDocument.swatches.length - 1;
var lastSwatch = app.activeDocument.swatches[lastIndex];
lastSwatch.name = "TheLastSwatch";
}