Copy link to clipboard
Copied
Hello everybody! I have a bunch of exported psd files from using variable data set. However, the filename is so hard to distinguish because, as you know, they are named by numerical order.
I am looking for a way to rename those files by the content of its top text layer (that text layer always at top). I tried to search but could not find any way to save the files as psd/psb. Any idea?
The following Photoshop script will rename a single open file in Photoshop.
Note that it's assumed that there are no illegal filename characters in the layer name. Use at your own risk.
#target photoshop
var theFile = File(activeDocument.fullName);
var theExt = app.activeDocument.name.replace(/(.+)(\.[^\.]+$)/, '$2');
var topLayerName = app.activeDocument.layers[0].name;
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
theFile.rename(topLayerName + theExt);
Untested: The script exec
...Yes, just setup the first column in the spreadsheet as the variable that you will link to the filename layer for text replacement when importing the data set.
When exporting the data sets as files, export using the data set name.
The final result with the files named after the first column:
Copy link to clipboard
Copied
Can you please post at least two different screenshots of the layers panel for each PSD file?
Or provide a sample PSD, which could be cropped or resized to 1px in size as only the layers are critical.
EDIT: Are you using the first variable spreadsheet column to name your files?
Copy link to clipboard
Copied
Thank you Sir for giving me a hand! This is my layers set, the 'filename' is always at the top and will also be filled with variable content, so it will be change with the set for sure:
For not to affect other contents, I will put the 'filename' far from the view area. The file will be saved as the content of this 'filename', so this is the only effect of this layer. I will send you a sample of this file
Copy link to clipboard
Copied
Looking at the screenshot the previous ExifTool or two Photoshop scripts should do the job as you are not using layer groups or artboards.
I'd still look at using the first variable to name the output files rather than having to rename them afterwards.
Copy link to clipboard
Copied
Yes, just setup the first column in the spreadsheet as the variable that you will link to the filename layer for text replacement when importing the data set.
When exporting the data sets as files, export using the data set name.
The final result with the files named after the first column:
Copy link to clipboard
Copied
Work on copies to ensure that the files are renamed correctly, if not you can always delete the misnamed copies.
Note that it's assumed that there are no illegal filename characters in the layer name. Use at your own risk.
The following ExifTool command line code will rename the files using the top layer name:
exiftool '-filename<${Photoshop:LayerNames;s/(^.+)(, )(.+$)/$3/}.%e'
Notice that there is a word space at the end of the code (indicated with the underline). After this space, you would drag the files or the folder containing the files into the command prompt window to complete the path and then press return to execute the command. MS Windows would use double-straight " quotes rather than single as used on the Mac.
This should also be possible using a script for Photoshop, however, it will be more complicated.
Copy link to clipboard
Copied
The following Photoshop script will rename a single open file in Photoshop.
Note that it's assumed that there are no illegal filename characters in the layer name. Use at your own risk.
#target photoshop
var theFile = File(activeDocument.fullName);
var theExt = app.activeDocument.name.replace(/(.+)(\.[^\.]+$)/, '$2');
var topLayerName = app.activeDocument.layers[0].name;
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
theFile.rename(topLayerName + theExt);
Untested: The script execution could be recorded into an action, and then the action could be run via the batch command on multiple open files.
EDIT - This one will batch-process all selected files:
/*
Rename Selected Files to Top Text Layer Name.jsx
v1.0 - 23rd August 2024, Stephen Marsh
https://community.adobe.com/t5/photoshop-ecosystem-discussions/export-variable-files-with-the-name-of-top-layer-s-content/td-p/14815858
*/
#target photoshop
(function () {
try {
if (app.documents.length === 0) {
var savedDisplayDialogs = app.displayDialogs;
var selectFiles = File.openDialog("Select the file/s:", Multiselect = true);
if (selectFiles === null) {
return;
}
for (var i = 0; i < selectFiles.length; i++) {
app.open(File(selectFiles[i]));
if (app.activeDocument.layers[0].kind == LayerKind.TEXT) {
var theFile = File(app.activeDocument.fullName);
var theExt = app.activeDocument.name.replace(/(.+)(\.[^\.]+$)/, '$2');
var topLayerName = app.activeDocument.layers[0].name;
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
theFile.rename(topLayerName + theExt);
} else {
alert("The top layer isn't a text layer!")
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}
}
app.displayDialogs = savedDisplayDialogs;
app.beep();
} else {
alert('Please close all open documents before running this script!');
}
} catch (err) {
alert("Error!" + "\r" + err + "\r" + 'Line: ' + err.line);
}
})();
Copy link to clipboard
Copied
Thank you very much! I missed your reply so haven't marked it before ^^ This is very useful
Find more inspiration, events, and resources on the new Adobe Community
Explore Now