Copy link to clipboard
Copied
Hello All!
I am working on a script to change the font color of all text layers of all files in a folder. I have modified script from a previous solution with mixed results. The script cycles through all the files but will not update the text layers as required.
Thanks for your help!
var textColor = new SolidColor();
textColor.rgb.hexValue = "111111"; //set color
//select folder where PSDs are held
var selectFolder = Folder.selectDialog( "Please select folder of PSDs");
var files = selectFolder.getFiles("*.psd");
//get an array of all PSDs in the folder
var fileList = selectFolder.getFiles("*.psd");
//iterate through file list
for (var i = 0; i < files.length; i++) {
var doc = app.open(files[i]);
for (var j= 0; j < doc.artLayers.length; j++) {
var lyr = doc.artLayers[j];
if (lyr.kind == LayerKind.TEXT) {
var lyr = doc.artLayers[j];
lyr.textItem.color = textColor;
}
}
doc.close(SaveOptions.SAVECHANGES)
}
1 Correct answer
Try the following code
var textColor = new SolidColor();
textColor.rgb.hexValue = "57a878"
function colorTextLayer(layerCol)
{
var layerCount = layerCol.length;
for (var j = layerCount - 1; j >= 0; j--)
{
var l = layerCol[j]
if(l.typename == "LayerSet")
colorTextLayer(layerCol[j].layers)
else
{
if (l.kind == LayerKind.TEXT)
l.textItem.color = textColor;
}
}
}
var selectFolder = Folder.selectDialog( "Please select folder of PSDs");
var files = selectFolder.getFiles("*
...
Explore related tutorials & articles
Copy link to clipboard
Copied
What issue do you get, as far as I can see the code should work. The only issue I can see is that this will work only on the artlayers that are not in any groups. If this is the case then search the forum for sample code that iterates over all the layers in the document and integrate it into your script.
-Manan
Copy link to clipboard
Copied
Thank you Manan! This explains my problem as my text files are located in a group. Now my second problem, many scripts need to you to address the specfic group name, however my group names are variable.
#target photoshop
var doc = activeDocument;
var selectedGroup = doc.layers.getByName('Colors');
doc.activeLayer = selectedGroup;
var reset = true;
loopLayers (selectedGroup)//turn off visibility
reset = false;
loopLayers (selectedGroup)//run loop again to run your inserted code
function loopLayers(gp){
for(var i=0;i<gp.layers.length;i++){
if(gp.layers.typename =='LayerSet'){
loopLayers (gp.layers);
}
else if(reset){
gp.layers.visible = false;
}
else{
gpLayers.visible = true;
//enter code here to save or whatever
gpLayers.visible = false;
}
}
}
Copy link to clipboard
Copied
Could you please post a screenshot of a failed file with the pertinent Panels (Toolbar, Layers, Channels, Options Bar, …) visible?
Copy link to clipboard
Copied
Try the following code
var textColor = new SolidColor();
textColor.rgb.hexValue = "57a878"
function colorTextLayer(layerCol)
{
var layerCount = layerCol.length;
for (var j = layerCount - 1; j >= 0; j--)
{
var l = layerCol[j]
if(l.typename == "LayerSet")
colorTextLayer(layerCol[j].layers)
else
{
if (l.kind == LayerKind.TEXT)
l.textItem.color = textColor;
}
}
}
var selectFolder = Folder.selectDialog( "Please select folder of PSDs");
var files = selectFolder.getFiles("*.psd");
//get an array of all PSDs in the folder
var fileList = selectFolder.getFiles("*.psd");
//iterate through file list
for (var i = 0; i < files.length; i++)
{
var doc = app.open(files[i]);
colorTextLayer(doc.layers)
doc.close(SaveOptions.SAVECHANGES)
}
-Manan
Copy link to clipboard
Copied
Hello.
The script halped me a lot in changing the text color of multiple psd files, however, is it possible to set the color hex value to be taken from the psd file name? I have bunch of psd files with only one text layer inside, each psd is named after a hex color value (example: #111111.psd) and they are all different. What I nedd to do is to change the text color inside every psd according to the file name that psd has.
Thank you in advance
Copy link to clipboard
Copied

