Copy link to clipboard
Copied
Hi everyone,
Here is the thing:
1) Bunch of psd files. Each file has 1 text layer inside. Each file is named after a hex color code (example: #111111.psd, #00ff00.psd, #ab6fe2.psd etc., there are about 300 of them)
2) The script below is to colorize all the text layers at ones. I found it from other discussion here
The problem:
- I need all psd files to have the text inside colored according to the file name of each psd. How to set the text color to be "taken" from the file name of each psd and not just set as one specific color? This script makes all text in all psd to have the same color, which is not what is needed.
Thanks in advance
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)
}
Try this slight modification to the original code from @Manan Joshi –
#target photoshop
// input folder
var selectFolder = Folder.selectDialog("Please select folder of PSDs");
// get an array of all PSDs in the folder
var files = selectFolder.getFiles("*.psd");
// iterate through file list
for (var i = 0; i < files.length; i++) {
var doc = app.open(files[i]);
// filename #ffffff.psd to hex ffffff
var hexCode = app.activeDocument.name.replace(/\#/, '').replace(/\.[^\.]+$/, '');
...
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Thanks, but this is where I got the above code from. And I also left same question there too, but thought it would be better idea to post it as separate discussion.
Copy link to clipboard
Copied
@default6keyane8hq42 wrote:
Thanks, but this is where I got the above code from. And I also left same question there too, but thought it would be better idea to post it as separate discussion.
Now the same question appears in two separate topic threads... Perhaps go to the original topic thread and change your post so that it points to this topic, so that you are not asking the same question in two separate places, which may waste the time of forum members answering something that has already been answered.
Please use the button to insert code text as javascript formatted code rather than plain text:
You would need to extract the hex code from the filename to a variable, then use the variable instead of the static code, similar to:
var hexCode = app.activeDocument.name.replace(/(?:\#)(.{6})(?:\.[^\.]+$)/, '$1');
Then you would need to use the variable to colour the text, perhaps something similar to:
eval('textColor.rgb.hexValue = "' + hexCode + '"');
It will not be that easy though, however I believe that is the general idea...
Copy link to clipboard
Copied
Try this slight modification to the original code from @Manan Joshi –
#target photoshop
// input folder
var selectFolder = Folder.selectDialog("Please select folder of PSDs");
// get an array of all PSDs in the folder
var files = selectFolder.getFiles("*.psd");
// iterate through file list
for (var i = 0; i < files.length; i++) {
var doc = app.open(files[i]);
// filename #ffffff.psd to hex ffffff
var hexCode = app.activeDocument.name.replace(/\#/, '').replace(/\.[^\.]+$/, '');
// call the function
colorTextLayer(doc.layers);
// close and save
doc.close(SaveOptions.SAVECHANGES);
}
// end of script notification
app.beep();
alert('Finished!');
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 {
var textColor = new SolidColor();
// static value
// textColor.rgb.hexValue = "ffffff"
// run filename to hexCode variable string as a statement
eval('textColor.rgb.hexValue = "' + hexCode + '"');
if (l.kind === LayerKind.TEXT)
l.textItem.color = textColor;
}
}
}
NOTE: There is no error checking to ensure that the filename will produce a valid hex colour code.
Copy link to clipboard
Copied
OMG it worked!!! Perfectly! Thank you so much!
Copy link to clipboard
Copied
Your welecome!
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more