Color change script based on style
Hey, this might be a rookie question, but i cant fix this, I got this script that changes the text color based on its style, really simple. Here it is for reference.
var doc = app.activeDocument;
function changeColorByFont(target) {
var layers = target.layers;
for (var i = 0; i < layers.length; i++) {
if (layers[i].typename == "LayerSet") {
changeColorByFont(layers[i]);
} else if (layers[i].kind == LayerKind.TEXT) {
var textItems = layers[i].textItem.contents.split('\r'); // Split text by line breaks
for (var j = 0; j < textItems.length; j++) {
var fontName = layers[i].textItem.font;
switch (fontName) {
case "Bebas-Regular": // Replace "Font1" with the actual name of your first font
layers[i].textItem.color.rgb.red = 255; // Red color
break;
case "CCWildWords-Italic": // Replace "Font2" with the actual name of your second font
layers[i].textItem.color.rgb.blue = 255; // Blue color
break;
case "CCJScottCampbell-Italic": // Replace "Font3" with the actual name of your third font
layers[i].textItem.color.rgb.black = 0; // Black color
break;
// Add more cases for additional fonts and colors as needed
}
}
};
};
};
changeColorByFont(doc);It works just fine when dealing with just one single font per layer, but when i mix 2 or more fonts it kinda messes up the thing, heres a visual example.


Is there any way to make it check and change every font in a text layer instead of the most used? Thanks.
