Changing font color with UXP

Hi,

I have a CEP panel that i’m trying to convert to UXP. I had a fonction that change the color of the selected text layer.

Using Alchemist for Photoshop, i can get the batchPlay function and properties, and i’m able to change the color of the text, however it also chage every property of the text layer (font, size, kerning etc). If i dont put these property, they reset to a default state, which also change all the properties.

Anybody know how to change a property without affecting all the others ?

batchPlay(
	    [{
	        "_obj": "set",
	        "_target": [{
	            "_ref": "layer",
	            "_enum": "ordinal",
	            "_value": "targetEnum"
	        }],
	        "to": {
	            "_obj": "textLayer",
	        	"textStyleRange": [
	            {
	               "_obj": "textStyleRange",
	               "from": 0,
	               "to": 10,
	               "textStyle": {
	                  "_obj": "textStyle",
	                  	"color": {
	                     "_obj": "RGBColor",
	                     "red": 0,
	                     "grain": 0,
	                     "blue": 0
	                  }
	                }
	            }]


	        },
	      "_isCommand": true,
	      "_options": {
	         "dialogOptions": "dontDisplay"
	      }
	   }
	],{
	   "synchronousExecution": false,
	   "modalBehavior": "fail"
	});

Try this:

batchPlay(
[
   {
      _obj: "set",
      _target: [
         {
            _ref: "property",
            _property: "textStyle"
         },
         {
            _ref: "textLayer",
            _enum: "ordinal",
            _value: "targetEnum"
         }
      ],
      to: {
         _obj: "textStyle",
         color: {
            _obj: "RGBColor",
            red: 0,
            grain: 0,
            blue: 0
         }
      },
      _options: {
         dialogOptions: "dontDisplay"
      }
   }
],{
   synchronousExecution: false,
   modalBehavior: "execute"
}); 

Wow ! It works. Your amazing.

What was the main problem ? TextStyleRange or the target property ?

I’m not sure how you got your result via Alchemist, but I tried it and got something more like the result I posted. Sometimes it is worth trying to make the change you want in the different ways you can in photoshop and looking at if you get different results in Alchemist.
For example, text color can be set in the properties panel, the character panel, by the text tool, etc.

If you enter into modal state of text layer (mode where you can type additional text) it usually returns very long descriptor that contains literally everything about text. But outside of modal state you more likely get just single purpose descriptors to change something. The disadvantage is that it will apply for whole text instead of text range in it.