• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Swatches name from color values

Contributor ,
Sep 22, 2014 Sep 22, 2014

Copy link to clipboard

Copied

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..

TOPICS
Actions and scripting

Views

1.6K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
Sep 22, 2014 Sep 22, 2014

Copy link to clipboard

Copied

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

Please elaborate.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Sep 23, 2014 Sep 23, 2014

Copy link to clipboard

Copied

Thanks for the reply,

. Swatch.JPG

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..

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 23, 2014 Sep 23, 2014

Copy link to clipboard

Copied

I have rgb() values and I want to get the name of the swatches that the document have corresponding to those rgb values.

As far as I can tell Photoshop Documents don’t have Swatches, the Application does.

But semantics aside I suspect the task might be a problematic one.

Have you looked around on ps-script.com yet?

ps-scripts.com • View topic - Managing Color Swatches

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Sep 23, 2014 Sep 23, 2014

Copy link to clipboard

Copied

As far as I can tell Photoshop Documents don’t have Swatches, the Application does.

Sorry for my ignorance..

I had looked into it but I didn't find anything useful in their, related to my task..

Although It seems like there, we can get the list of swatches name and from the name we can get the color values. And after that I can match the values with the fill color of selected art object.

What I am looking here something like, set the rgb values in the keys and by using action manager code I can get the swatch name.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 23, 2014 Sep 23, 2014

Copy link to clipboard

Copied

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"));

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Sep 23, 2014 Sep 23, 2014

Copy link to clipboard

Copied

Thanks for the help..

I will try it.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 23, 2014 Sep 23, 2014

Copy link to clipboard

Copied

It would be a round-about way – getting the names, then using the names to get the colours, then comparing those to the Foreground Color (or whatever).

Hopefully someone else can offer more insight … but as you marked this thread as answered others may not pay it much mind so you might want to start a new thread if the method proves too cumbersome.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 25, 2015 May 25, 2015

Copy link to clipboard

Copied

LATEST

can get  any color swatches  color name and  color value by javascript?  xbytor’s xtools’ Scripts "ColorSwatches.jsx" and "Stream.js" can't run photoshop cc

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines