Is it possible to add text-color to color-swatch?
Hi!
I linked two function scripts but it doesn't work...
the Js code is below_
//alert("Text color: " + getFontInfo());
function getFontInfo() {
/* Based on code from the late Michael Hale
https://community.adobe.com/t5/photoshop-ecosystem-discussions/how-to-get-color-info-of-text-in-text-layer/m-p/3342131
*/
var ref = new ActionReference();
ref.putEnumerated(stringIDToTypeID("layer"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
var desc = executeActionGet(ref);
var list = desc.getObjectValue(charIDToTypeID("Txt "));
var tsr = list.getList(charIDToTypeID("Txtt"));
var info = [];
for (var i = 0; i < tsr.count; i++) {
var tsr0 = tsr.getObjectValue(i);
var textStyle = tsr0.getObjectValue(charIDToTypeID("TxtS"));
var color = textStyle.getObjectValue(charIDToTypeID('Clr '));
var textColor = new SolidColor();
textColor.rgb.red = color.getDouble(charIDToTypeID('Rd '));
textColor.rgb.green = color.getDouble(charIDToTypeID('Grn '));
textColor.rgb.blue = color.getDouble(charIDToTypeID('Bl '));
//info.push([textColor.rgb.red.toFixed(), textColor.rgb.green.toFixed(), textColor.rgb.blue.toFixed()]);
}
//return info;
}
var red = textColor.rgb.red.toFixed();
var blue = textColor.rgb.green.toFixed();
var green = textColor.rgb.blue.toFixed();
var addColorDescriptor = new ActionDescriptor();
// Get reference to Swatches panel
var swatchesPanelReference = new ActionReference();
swatchesPanelReference.putClass(stringIDToTypeID('colors'));
addColorDescriptor.putReference(stringIDToTypeID('null'), swatchesPanelReference);
// Setup a swatch and give it a name
var descriptorSwatch = new ActionDescriptor();
descriptorSwatch.putString(stringIDToTypeID('name'), name);
// Add RGB color information to the swatch
var descriptorColor = new ActionDescriptor();
descriptorColor.putDouble(stringIDToTypeID('red'), red);
descriptorColor.putDouble(stringIDToTypeID('grain'), green); // grain = green
descriptorColor.putDouble(stringIDToTypeID('blue'), blue);
// Add RGB to the swatch
descriptorSwatch.putObject(stringIDToTypeID('color'), stringIDToTypeID('RGBColor'), descriptorColor);
// Add swatch to the color descriptor
addColorDescriptor.putObject(stringIDToTypeID('using'), stringIDToTypeID('colors'), descriptorSwatch);
// Send to Photoshop
executeAction(stringIDToTypeID('make'), addColorDescriptor, DialogModes.NO);
----
I want to add text color to color-swatch but above script only add white color.
Could I get some help? T T
