Skip to main content
Inspiring
August 21, 2015
Question

delete swatch

  • August 21, 2015
  • 1 reply
  • 498 views

Hi.

My goal is to have a script that erases all swatches on the Swatches panel.

I'm working on a project with maps for lots of different data. The clients gave me jpgs with the map and the legend, and I need to extract the colors in the legends and save them as swatches, so I can export them and use the same collection of swatches in Photoshop and InDesign. To get a swatch collection with only the colors I need, I have to erase all the swatches already on the Swatches panel and then add mine. I've been doing this manually, which is tedious work.

I've scripted before for InDesign, but I can't find a way to get manipulate swatches or the Swatches panel in Photoshop. Can anyone help me with this?

Thank you.

This topic has been closed for replies.

1 reply

c.pfaffenbichler
Community Expert
Community Expert
August 21, 2015

You may have to use Action Manager code, as recorded with ScriptingListener.plugin.

As for deleting all swatches this should help (edited):

// 2015, use it at your own risk;

#target photoshop

// based on mike hale’s code;

var ref = new ActionReference();

ref.putProperty(stringIDToTypeID('property'), stringIDToTypeID('presetManager'));// the presets list

ref.putEnumerated( charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

var desc = executeActionGet(ref);// get the app descriptor

var presetsList = desc.getList(stringIDToTypeID('presetManager'));// the presets list

var swatchDesc = presetsList.getObjectValue(1);// swatches is the second key

var nameList = swatchDesc.getList(charIDToTypeID("Nm  "));// there is only one key in the swatch descriptor so get the list

for (var m = 0; m < nameList.count; m++) {

// =======================================================

var idDlt = charIDToTypeID( "Dlt " );

    var desc2 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

        var ref1 = new ActionReference();

        var idClrs = charIDToTypeID( "Clrs" );

        ref1.putIndex( idClrs, 1 );

    desc2.putReference( idnull, ref1 );

executeAction( idDlt, desc2, DialogModes.NO );

};

Inspiring
November 17, 2015

Thank you, and sorry for the delay in replying to you.