Skip to main content
Inspiring
September 22, 2014
Question

Swatches name from color values

  • September 22, 2014
  • 1 reply
  • 2682 views

Hi all,

How can we get the swatch name from its color value?

I looked into the photoshop scripting APIs but couldn't find anything related to swatches.

Thanks for any help..

This topic has been closed for replies.

1 reply

c.pfaffenbichler
Community Expert
Community Expert
September 22, 2014
How can we get the swatch name from its color value?

Please elaborate.

Inspiring
September 23, 2014

Thanks for the reply,

.

Here is a swatch name 'RGB Green' with the color value rgb(0, 255, 0). Now what I want here is that, I have rgb() values and I want to get the name of the swatches that the document have corresponding to those rgb values.

Does it make sense?

Actually I have a selected object and I am getting its fill color and from that color value I want to get the swatch name if any.

Thanks..

Inspiring
September 23, 2014

Using xbytor’s xtools’ Scripts "ColorSwatches.jsx" and "Stream.js" one can get a Swatch’s color, albeit … the Swatch is being identified by name and it seems possible to have more than one swatch with the same name in the Panel.

$.evalFile("/*insert the correct path here*/ColorSwatches.jsx");

$.evalFile("/*insert the correct path here*/Stream.js");

var theName = /*insert the name as a string here*/;

alert (ColorSwatches.getColor(theName).rgb.red+"_"+ColorSwatches.getColor(theName).rgb.green+"_"+ColorSwatches.getColor(theName).rgb.blue);

To get a list of the Swatches’ names one can use this:

// based on mike hale’s code;

var ref = new ActionReference();

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

var theNames = new Array;

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

theNames.push(nameList.getString(m))

};

alert (theNames.join("\n"));


Thanks for the help..

I will try it.