5 Replies Latest reply on Nov 11, 2013 9:17 AM by boo radley 2013

    Changing Layer Color

    boo radley 2013 Level 3

      Hi, here's a script which changes the layer's color (the 'eye' icon) to blue:

       

      function setCurrentLayerBlue() {

        function cTID(s) { return app.charIDToTypeID(s); };

        function sTID(s) { return app.stringIDToTypeID(s); };

       

          var desc5 = new ActionDescriptor();

              var ref3 = new ActionReference();

              ref3.putEnumerated( cTID('Lyr '), cTID('Ordn'), cTID('Trgt') );

          desc5.putReference( cTID('null'), ref3 );

              var desc6 = new ActionDescriptor();

              desc6.putEnumerated( cTID('Clr '), cTID('Clr '), cTID('Bl  ') );

          desc5.putObject( cTID('T   '), cTID('Lyr '), desc6 );

          executeAction( cTID('setd'), desc5, DialogModes.NO );

      };

       

      setCurrentLayerBlue();

       

       

      and it works fine. But I can't get some of the other colors to work, such as Orange. I switched up the 'Blue' to 'Orange' and 'Blu' to "Orng' so I was hoping it would work but it isn't:

       

      function setCurrentLayerOrange() {

        function cTID(s) { return app.charIDToTypeID(s); };

        function sTID(s) { return app.stringIDToTypeID(s); };

       

          var desc5 = new ActionDescriptor();

              var ref3 = new ActionReference();

              ref3.putEnumerated( cTID('Lyr '), cTID('Ordn'), cTID('Trgt') );

          desc5.putReference( cTID('null'), ref3 );

              var desc6 = new ActionDescriptor();

              desc6.putEnumerated( cTID('Clr '), cTID('Clr '), cTID('Orng  ') );

          desc5.putObject( cTID('T   '), cTID('Lyr '), desc6 );

          executeAction( cTID('setd'), desc5, DialogModes.NO );

      };

       

      setCurrentLayerOrange();

        • 1. Re: Changing Layer Color
          Chuck Uebele Adobe Community Professional & MVP

          Did you run scriptListener for each color, just to get the descriptor name?  Guessing is like trying to pick a safe combo.

          • 2. Re: Changing Layer Color
            boo radley 2013 Level 3

            geez I didn't even think of that.. how could I forget... I'll try it and report back..

            • 3. Re: Changing Layer Color
              boo radley 2013 Level 3

              worked fine... don't know why I didn't think of that in the first place..

               

              here's another script which used to change the layer color to a darker green than the standard green:

               

              function setCurrentLayerDarkGreen() {

                function cTID(s) { return app.charIDToTypeID(s); };

                function sTID(s) { return app.stringIDToTypeID(s); };

               

                  var desc5 = new ActionDescriptor();

                      var ref3 = new ActionReference();

                      ref3.putEnumerated( cTID('Lyr '), cTID('Ordn'), cTID('Trgt') );

                  desc5.putReference( cTID('null'), ref3 );

                      var desc6 = new ActionDescriptor();

                      desc6.putEnumerated( cTID('Clr '), cTID('Clr '), cTID('Gr  ') );

                  desc5.putObject( cTID('T   '), cTID('Lyr '), desc6 );

                  executeAction( cTID('setd'), desc5, DialogModes.NO );

              };

               

              setCurrentLayerDarkGreen();

               

               

              ..and it actually worked - it changed it to a deep green which isn't available as a standard color. But for some reason it won't work now.

               

              Having said that, could there be a way to change the layer colors to other colors which aren't in the menu? (Pink, brown, or any other color we can think of) ?

              • 4. Re: Changing Layer Color
                Michael L Hale Level 5

                ..and it actually worked - it changed it to a deep green which isn't available as a standard color. But for some reason it won't work now.

                It doesn't work for me. In fact if the layer already has a color this will set the color to none, removing the existing layer color.

                 

                Even if it did work I wouldn't recommend tying to do something that is not supported by the GUI. I think it might cause problems to have unexpected colors in the layer descriptor.

                • 5. Re: Changing Layer Color
                  boo radley 2013 Level 3

                  yeah it used to work - I was fascinated when I could change the color to a deep green - I always thought we were restricted to the 7 default colors (red blue yellow green violet orange gray). I don't know what went wrong though... it may have had something to do with an earlier version of Photoshop but it won't run on a more recent version. Ah well, not a big deal