• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Script to change font color of multiple layers in multiple files

New Here ,
Nov 25, 2020 Nov 25, 2020

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)

}

TOPICS
Actions and scripting

Views

466

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Nov 26, 2020 Nov 26, 2020

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("*
...

Votes

Translate

Translate
Adobe
Community Expert ,
Nov 25, 2020 Nov 25, 2020

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 26, 2020 Nov 26, 2020

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;

            }

        }

    }

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 26, 2020 Nov 26, 2020

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? 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 26, 2020 Nov 26, 2020

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 04, 2021 Dec 04, 2021

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 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 05, 2021 Dec 05, 2021

Copy link to clipboard

Copied

LATEST

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines