Skip to content

Swatches

app.activeDocument.swatches

The collection of Swatch objects in the document.


app.activeDocument.swatches.length

Number of elements in the collection.

Number; read-only.


app.activeDocument.swatches.parent

The object’s container.

Object; read-only.


app.activeDocument.swatches.typename

The class name of the object.

String; read-only.


app.activeDocument.swatches.add()

Creates a new Swatch object.

Swatch


app.activeDocument.swatches.getByName(name)

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

ParameterTypeDescription
nameStringName of element to get

Swatch


app.activeDocument.swatches.getSelected()

Gets selected swatches in the document.

List of Swatch


app.activeDocument.swatches.index(itemKey)

Gets an element from the collection.

ParameterTypeDescription
itemKeyString, NumberKey of element to get

Swatch


app.activeDocument.swatches.removeAll()

Deletes all elements in the collection.

Nothing.


// Deletes swatch 4 from the current document
if ( app.documents.length > 0 ) {
if (app.activeDocument.swatches.length > 4) {
var swatchToDelete = app.activeDocument.swatches[3];
swatchToDelete.remove();
}
}