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

Automate file naming according to Group name in Photoshop

Community Beginner ,
Oct 14, 2019 Oct 14, 2019

Greetings.
I'm looking for a way to automate file naming according to layer group name.

I have a PSD file with several layer groups in it. The task is to export several JPG versions of this PSD file, with each version including a specific layer group content only. And each JPG must be named accordingly to it's layer group.

For example:
The PSD name is 2020.01.01 Artist (US Tour).psd.
It contains three layer groups named:
2020.01.02 Artist (New York)
2020.01.03 Artist (Boston)
2020.01.04 Artist (Philadelphia)

I need every layer group to be exported as JPG, and these JPG files must be automatically named after their layer groups.

Is there a script that can automate this process?
Thanks a lot.

 

{Thread renamed by moderator}

TOPICS
Actions and scripting
3.3K
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 1 Correct answer

Community Expert , Oct 14, 2019 Oct 14, 2019

Okay, this script will export all the top level groups, into the same folder, and use the group name as the file name. It will leave the visibility on of any layer not in one of the groups.

#target photoshop
var jpgOptions = new JPEGSaveOptions();
jpgOptions.quality = 8;
var doc = activeDocument;
var dPath = doc.path
var gArray = new Array();

for(var i=0;i<doc.layers.length;i++){
    doc.activeLayer = doc.layers[i];
    if(doc.layers[i].typename == 'LayerSet'){
        gArray.push(doc.layers[i]
...
Translate
Adobe
Adobe Employee ,
Oct 14, 2019 Oct 14, 2019

Hi There,

Welcome to the Adobe Community!

As you're looking to automate file naming according to layer group name, please have a look at a similar discussion here and see if it helps: Export Groups to Files?


You may also have a look at this and let us know how it goes: Exporting Groups (Folders) to Files in Photoshop

 

Regards,
Sahil

 

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
LEGEND ,
Oct 14, 2019 Oct 14, 2019

You linked us to a thread started in 2009? How that is possible if new forum stores topics no older than from after 2016. Is it because later replies to that thread were posted in in February of 2019? So I mean if not the fact of refreshing topic after 10 years that one would be lost (like others old-current users reported, or just archived, but where if I may know it)?

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 ,
Oct 14, 2019 Oct 14, 2019
I'm not sure, but not all old threads were archived, but I'd like to know also.
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 ,
Oct 14, 2019 Oct 14, 2019

For each group, are all the layers that you need exported visible, or do they need to be turned on for exporting with the group?

Also, are all the groups that you want to export on the top level - not in another layerset?

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 Beginner ,
Oct 14, 2019 Oct 14, 2019

All the layers within every group are visible. And all the groups are on the top level.

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 ,
Oct 14, 2019 Oct 14, 2019

Do you have a background layer that has to be visible and exported with all the groups?

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 Beginner ,
Oct 14, 2019 Oct 14, 2019
Yes, there is a common background layer that has to be exported with every group. For example: the background layer is a blank poster, and every group contains text info and png logos for every date of the tour.
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 ,
Oct 14, 2019 Oct 14, 2019

Okay, this script will export all the top level groups, into the same folder, and use the group name as the file name. It will leave the visibility on of any layer not in one of the groups.

#target photoshop
var jpgOptions = new JPEGSaveOptions();
jpgOptions.quality = 8;
var doc = activeDocument;
var dPath = doc.path
var gArray = new Array();

for(var i=0;i<doc.layers.length;i++){
    doc.activeLayer = doc.layers[i];
    if(doc.layers[i].typename == 'LayerSet'){
        gArray.push(doc.layers[i]);
        doc.layers[i].visible = false;
        }        
    }

for(var i=0;i<gArray.length;i++){
    gArray[i].visible = true;
    var gName = gArray[i].name;
    $.writeln(gName)
    doc.saveAs (new File(dPath +'/' + gName + '.jpg'), jpgOptions,true);
    gArray[i].visible = false;
    };

for(var i=0;i<gArray.length;i++){
    gArray[i].visible = true;
    };
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 Beginner ,
Oct 14, 2019 Oct 14, 2019

That was quick! Your script works and it's amazing, thanks a lot!

Is there a chance to upgrade it a bit? There's a background layer group with poster art and 3 layer groups with text info and logos. How can we automate the export of JPG posters keeping the background layer group the same but applying different layer groups with show info? As a result I need to have 3 different JPGs exported (one per each city), and every of them must have the same background.

I attached a PSD file so you can test it. Thanks a lot again!

Screenshot.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 Beginner ,
Oct 14, 2019 Oct 14, 2019
Just updated my answer, can you check please? Thank you
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 ,
Oct 14, 2019 Oct 14, 2019

Okay, this script will exclude changing the group Backgroug Group. Just keep that name the same in all your files!

#target photoshop
var jpgOptions = new JPEGSaveOptions();
jpgOptions.quality = 8;
var doc = activeDocument;
var dPath = doc.path
var gArray = new Array();

for(var i=0;i<doc.layers.length;i++){
    doc.activeLayer = doc.layers[i];
    if(doc.layers[i].typename == 'LayerSet' && doc.layers[i].name.toLowerCase() != 'background group'){
        gArray.push(doc.layers[i]);
        doc.layers[i].visible = false;
        }        
    }

for(var i=0;i<gArray.length;i++){
    gArray[i].visible = true;
    var gName = gArray[i].name;
    $.writeln(gName)
    doc.saveAs (new File(dPath +'/' + gName + '.jpg'), jpgOptions,true);
    gArray[i].visible = false;
    };

for(var i=0;i<gArray.length;i++){
    gArray[i].visible = true;
    };

 

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 Beginner ,
Oct 14, 2019 Oct 14, 2019
Works perfectly, thank you so much! And one last thing. How can I change the exporting directory to "Downloads" folder? (Or any other path). Was playing with " dPath +'/' " but it didn't work as I'm not familiar with scripting. Thanks again
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 ,
Oct 14, 2019 Oct 14, 2019

Are you on Win or Mac?

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 Beginner ,
Oct 14, 2019 Oct 14, 2019
I'm on Mac
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 ,
Oct 14, 2019 Oct 14, 2019

If you're on Win, this is the path to get to the download folder. Currently the dPath just gets the path for the current file. The "`" will point to the current users folder.

var dPath = new Folder('~/Downloads/');
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 ,
Oct 14, 2019 Oct 14, 2019

I'm not sure where the download folder is on the Mac, but the "`" should still point to the user's folder.

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 ,
Oct 14, 2019 Oct 14, 2019
LATEST

I have not tested, however that looks right Chuck as ('~/Desktop/‘) works and both folders are in the users home folder. So it should all come down to permissions.

 

EDIT: Yes it works!

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