8 Replies Latest reply on May 25, 2015 9:29 AM by roychen

    Swatches name from color values

    AI_learner Level 1

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

        • 1. Re: Swatches name from color values
          c.pfaffenbichler Level 9
          How can we get the swatch name from its color value?

          Please elaborate.

          • 2. Re: Swatches name from color values
            AI_learner Level 1

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

            • 3. Re: Swatches name from color values
              c.pfaffenbichler Level 9

              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

              • 4. Re: Swatches name from color values
                AI_learner Level 1

                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.

                • 5. Re: Swatches name from color values
                  c.pfaffenbichler Level 9

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

                  • 6. Re: Swatches name from color values
                    AI_learner Level 1

                    Thanks for the help..

                    I will try it.

                    • 7. Re: Swatches name from color values
                      c.pfaffenbichler Level 9

                      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.

                      • 8. Re: Swatches name from color values
                        roychen Level 1

                        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