4 Replies Latest reply on Nov 23, 2016 11:17 AM by juliel96058674

    Determine layer color label from layer id?

    juliel96058674 Level 1



      Does anyone know if it's possible to determine the layer color label that's shown to the left of the layer name? I tried to determine the color label using the following method, however this isn't returning the expected result. I'm using photoshop CC 2015.


      var ref = new ActionReference();

      ref.putIndex(charIDToTypeID('Lyr '), layer.id);

      var desc = executeActionGet(ref);

      var color = typeIDToStringID(desc.getEnumerationValue(stringIDToTypeID("color")));


      The color variable is consistently returning "grain". Please let me know if anyone knows how to get the color from the layer label.


      Thanks in advance!

        • 1. Re: Determine layer color label from layer id?
          SuperMerlin Level 5

          This is using the layer ID.


          function getLayerColourByID( ID ) { 
          var ref = new ActionReference(); 
          ref.putProperty( charIDToTypeID("Prpr") ,stringIDToTypeID('color')); 
          ref.putIdentifier(charIDToTypeID( "Lyr " ), ID );
          return typeIDToStringID(executeActionGet(ref).getEnumerationValue(stringIDToTypeID('color'))); 
          • 2. Re: Determine layer color label from layer id?
            pixxxel schubser MVP & Adobe Community Professional

            Hi juliel96058674,

            you can set the active layer label color:

            // layer_setLayerColor_layerLabel.jsx
            // "none","red","orange","yellowColor","grain","blue","violet","gray"
            // set the color you want
            // regards pixxxel schubser
            function layerLabel () {
                var target = new ActionDescriptor();
                    var ref1 = new ActionReference();
                    ref1.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
                target.putReference( charIDToTypeID('null'), ref1 );
                    var colorize = new ActionDescriptor();
                    colorize.putEnumerated( charIDToTypeID('Clr '), charIDToTypeID('Clr '), charIDToTypeID('None') );
                    //colorize.putEnumerated( charIDToTypeID('Clr '), charIDToTypeID('Clr '), charIDToTypeID("red") );
                target.putObject( charIDToTypeID('T   '), charIDToTypeID('Lyr '), colorize );
                executeAction( charIDToTypeID('setd'), target, DialogModes.NO );
            layerLabel ();



            you can get the active layer label color (IMHO years ago written by Paul Riggott )

            function getLayerColour(){
            //Colours returned .... 
            // "none","red","orange","yellowColor","grain","blue","violet","gray"
            var ref = new ActionReference();
               ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
               var appDesc = executeActionGet(ref);
              return typeIDToStringID(appDesc.getEnumerationValue(stringIDToTypeID('color')) );


            Have fun


            • 3. Re: Determine layer color label from layer id?
              Tom Ruark Adobe Employee

              stringIDToTypeID('grain') == stringIDToTypeID('green')


              Long long ago in a galaxy far far away we made a mistake and did this:


              #define keyGrain 'Grn ' // CONFLICT: keyGreen.

              and this


              #define keyGreen 'Grn ' // There is also an enumGreen. CONFLICT: keyGrain.


              And Photoshop invented a new color.


              I tried to fix once but there was too much "legacy" code and everyone voted to leave it alone...sorry.


              And add a ref.puProperty(... for that key) so you don't waste time getting ALL of the keys on the layer.

              • 4. Re: Determine layer color label from layer id?
                juliel96058674 Level 1

                Interesting, I was wondering where the "grain" color came from.. thanks