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

Export Variable files with the name of top layer's content

Participant ,
Aug 22, 2024 Aug 22, 2024

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?

TOPICS
Actions and scripting , Windows
819
Translate
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 2 Correct answers

Community Expert , Aug 23, 2024 Aug 23, 2024

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

...
Translate
Community Expert , Aug 24, 2024 Aug 24, 2024

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.

 

data-setup.png

The final result with the files named after the first column:

 

the-result.png

Translate
Adobe
Community Expert ,
Aug 23, 2024 Aug 23, 2024

@Zipser31550168t845 

 

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?

 

https://community.adobe.com/t5/photoshop-ecosystem-discussions/photoshop-datasets-changing-the-outpu...

 

Translate
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
Participant ,
Aug 24, 2024 Aug 24, 2024

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:

Zipser31550168t845_0-1724498269786.png

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

Zipser31550168t845_1-1724499944274.png

 

 

Translate
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 ,
Aug 24, 2024 Aug 24, 2024

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.

Translate
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 ,
Aug 24, 2024 Aug 24, 2024
LATEST

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.

 

data-setup.png

The final result with the files named after the first column:

 

the-result.png

Translate
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 ,
Aug 23, 2024 Aug 23, 2024

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.

 
Translate
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 ,
Aug 23, 2024 Aug 23, 2024

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);
        }

    })();

 

Translate
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
Participant ,
Aug 24, 2024 Aug 24, 2024

Thank you very much! I missed your reply so haven't marked it before ^^ This is very useful 

Translate
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