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

need script to export all layer names into an excel sheet or text file.

New Here ,
Oct 22, 2015 Oct 22, 2015

Copy link to clipboard

Copied

are there any scripts to export layer names into an excel sheet or a text file?

TOPICS
Actions and scripting

Views

9.7K

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
Adobe
Community Expert ,
Feb 16, 2021 Feb 16, 2021

Copy link to clipboard

Copied

Great, thanks for the thanks! Depending on end-use, further text/string manipulation may be required.

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 ,
Oct 01, 2021 Oct 01, 2021

Copy link to clipboard

Copied

Since this post, I have managed to write a script to both copy to the clipboard and also to save a csv of top-level layers names.

 

// Layer Names to CSV and Clipboard CR List.jsx
// Stephen Marsh, 2021
// Useful for creating a layer visibility data set for Data Driven Graphics / Variables

// Loop over top level layers and layer sets
var lyrCount = app.activeDocument.layers.length;
var lyrArray = [];
for (var i = 0; i < lyrCount; i++) {
    lyrArray[i] = app.activeDocument.layers[i].name;
}

// Layers to list and CSV
var list = lyrArray.toString().replace(/,/g, '\r');
var csv = lyrArray;

// Copy layer list to clipboard
var d = new ActionDescriptor();
d.putString(stringIDToTypeID('textData'), list);
executeAction(stringIDToTypeID('textToClipboard'), d, DialogModes.NO);

// Create a text file of the layer list
var textFile = new File('~/Desktop' + '/' + 'layerList.csv');
// r for read mode - w for write mode - a for append - e for edit
textFile.open('w');
textFile.encoding = 'UTF-8';
textFile.write(csv);
textFile.close();

// End of script notifications
app.beep();
alert('Top level layer list copied to clipboard and saved to .csv on desktop');

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
LEGEND ,
Oct 01, 2021 Oct 01, 2021

Copy link to clipboard

Copied

Here is an alternate way to get data to the Clipboard in Photoshop (this demo copies the filename)

#target photoshop

copyFilename();

function copyFilename(){
    try{
        if(documents.length > 0){
            var originalDialogMode = app.displayDialogs;
            app.displayDialogs = DialogModes.ERROR;
            var docRef = activeDocument;
            app.displayDialogs = originalDialogMode;
            }
        var cmd;
        var isWindows;
        isWindows = $.os.indexOf('Windows') != -1;
        if(isWindows){
            cmd = 'cmd.exe /c cmd.exe /c "echo ' + docRef.name + '| clip"';
            }
        else{
            cmd = 'echo ' + docRef.name + ' | pbcopy';
            }
        app.system(cmd);
        }
    catch(e){
        alert(e + e.line);
        }
    }

 

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
Explorer ,
Sep 06, 2022 Sep 06, 2022

Copy link to clipboard

Copied

This one is perfect, but how to get all layers in a row like in first script? Now everything is in one column? 😄
I see you are a magician in scripting!
So maybe you know if it is possible in technical way to create script which create variables from visible layers names? Right now I must select each and type with finger variable for each layer.
I try to create easy system > export layer names to csv > translate via sheets > import via variables > done
But PS is very limited this matter 
Screenshot_1.jpg

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
Explorer ,
Jan 09, 2022 Jan 09, 2022

Copy link to clipboard

Copied

Hi, having your original problem. How do I include both Folders and layer Names with this? Script newbie.

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 ,
Jan 10, 2022 Jan 10, 2022

Copy link to clipboard

Copied

It's above my pay grade I'm afraid, for many others here it isn't though!

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
Explorer ,
Aug 29, 2022 Aug 29, 2022

Copy link to clipboard

Copied

Can you make your script works with multiple artboards in one PSD document? I'm making banners on different artboards and on the end I need text data with all layers names. Your script works, but it's copying only artboard name and nothing deeper. Plz help

 

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 ,
Aug 29, 2022 Aug 29, 2022

Copy link to clipboard

Copied

Sorry, this will take somebody with more scripting knowledge and experience than I possess.

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
Guide ,
Aug 30, 2022 Aug 30, 2022

Copy link to clipboard

Copied

 

@Jakub25857702e4sw 

#target photoshop
var s2t = stringIDToTypeID,
    treeView = true;
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('json'));
r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));
eval('var layersCollection = ' + executeActionGet(r).getString(p).replace(/\\/g, ''));
var needToProcess = collectAdjustmentLayers(layersCollection.layers)
var f = new File('~/Desktop' + '/' + 'layerList.txt');
f.open('w');
f.encoding = 'UTF-8';
f.write(needToProcess.join('\n'));
f.close();
function collectAdjustmentLayers(layersObject, collectedLayers, tab) {
    collectedLayers = collectedLayers ? collectedLayers : [];
    tab = tab ? tab : '';
    for (var i = 0; i < layersObject.length; i++) {
        cur = layersObject[i];
        if (cur.layers) {
            collectedLayers.push(tab + cur.name)
            collectAdjustmentLayers(cur.layers, collectedLayers, treeView ? tab + '  ' : '')
        }
        else collectedLayers.push(tab + cur.name)
    }
    return collectedLayers;
}

 

* if you just want a one-column list, replace treeView = true; by treeView = 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 ,
Aug 30, 2022 Aug 30, 2022

Copy link to clipboard

Copied

A beautiful thing indeed jazz-y, thank you for sharing!

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
Explorer ,
Sep 06, 2022 Sep 06, 2022

Copy link to clipboard

Copied

SUPERB! I have one question, its possible to exclude not visible layer and skip duplicates? Im working on "translations" system with multiple artboards. Best solution its will be export to CVS only visibile layers and without duplicates so If is already 1 layer named XXX1 so its not shows up in file

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
Guide ,
Sep 06, 2022 Sep 06, 2022

Copy link to clipboard

Copied

#target photoshop
var s2t = stringIDToTypeID;
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('json'));
r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));
eval('var layersCollection = ' + executeActionGet(r).getString(p).replace(/\\/g, ''));
var needToProcess = collectLayers(layersCollection.layers)
var f = new File('~/Desktop' + '/' + 'layerList.txt');
f.open('w');
f.encoding = 'UTF-8';
for (var a in needToProcess) f.writeln(a)
f.close();
function collectLayers(layersObject, collectedLayers) {
    collectedLayers = collectedLayers ? collectedLayers : [];
    for (var i = 0; i < layersObject.length; i++) {
        var cur = layersObject[i];
        if (cur.visible) {
            if (cur.layers) {
                collectedLayers[cur.name] = true;
                collectLayers(cur.layers, collectedLayers)
            }
            else collectedLayers[cur.name] = true;
        }
    }
    return collectedLayers;
}

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
Explorer ,
Sep 06, 2022 Sep 06, 2022

Copy link to clipboard

Copied

This one is perfect, but how to get all layers in a row like in the first script you have made? Now everything is in one column? 

I see you are a magician in scripting!

So maybe you know if it is possible in technical way to create script which create variables from visible layers names? Right now I must select each and type with finger variable for each layer.
I try to create easy system > export layer names to csv > translate via sheets > import via variables > done
But PS is very limited this matter 
Screenshot_1.jpg

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
Guide ,
Sep 06, 2022 Sep 06, 2022

Copy link to clipboard

Copied

@Jakub25857702e4sw first version also formed one column. If you need values in one row - just replace the separator character with any convenient one in the following code, for example separator = ';'

 

#target photoshop
var s2t = stringIDToTypeID;
separator = ';';
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('json'));
r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));
eval('var layersCollection = ' + executeActionGet(r).getString(p).replace(/\\/g, ''));
var needToProcess = collectAdjustmentLayers(layersCollection.layers)
var f = new File('~/Desktop' + '/' + 'layerList.txt');
f.open('w');
f.encoding = 'UTF-8';
f.write(needToProcess.join(separator));
f.close();
function collectAdjustmentLayers(layersObject, collectedLayers, uniqueNames) {
    collectedLayers = collectedLayers ? collectedLayers : [];
    uniqueNames = uniqueNames ? uniqueNames : {};
    for (var i = 0; i < layersObject.length; i++) {
        var cur = layersObject[i];
        if (!uniqueNames[cur.name] && cur.visible) {
            uniqueNames[cur.name] = true;
            collectedLayers.push(cur.name)
        }
        if (cur.layers) collectAdjustmentLayers(cur.layers, collectedLayers, uniqueNames)
    }
    return collectedLayers;
}

 

I don't know of a way to set variables names using a script. Inside the binary image file, you can find a block with variables:

 

<variableSets xmlns="http://ns.adobe.com/Variables/1.0/">
<variableSet locked="none" varSetName="binding1">
<variables>
<variable varName="VisibilityVariable1" trait="visibility" docRef="id('273')">
</variable>
</variables>
</variableSet>
</variableSets>

 

However, it is quite difficult to create or modify it yourself (and not damage the file in the process).

 

@AnnaSto 

 

#target photoshop
var s2t = stringIDToTypeID;
separator = ';';
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('json'));
r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));
eval('var layersCollection = ' + executeActionGet(r).getString(p).replace(/\\/g, ''));
var needToProcess = collectAdjustmentLayers(layersCollection.layers)
var f = new File('~/Desktop' + '/' + 'layerList.txt');
f.open('w');
f.encoding = 'UTF-8';
f.write(needToProcess.join(separator));
f.close();
function collectAdjustmentLayers(layersObject, collectedLayers, uniqueNames) {
    collectedLayers = collectedLayers ? collectedLayers : [];
    uniqueNames = uniqueNames ? uniqueNames : {};
    for (var i = 0; i < layersObject.length; i++) {
        var cur = layersObject[i];
        if (!uniqueNames[cur.name] && cur.visible && cur.type != 'layerSection' && cur.type != 'artboardSection') {
            uniqueNames[cur.name] = true;
            collectedLayers.push(cur.name)
        }
        if (cur.layers) collectAdjustmentLayers(cur.layers, collectedLayers, uniqueNames)
    }
    return collectedLayers;
}

 

 

 

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 ,
Sep 06, 2022 Sep 06, 2022

Copy link to clipboard

Copied

Dear Jazz, I have the same problem. I need a list in one row of visible layers only but without duplicates and folder names and artboards names, only a list of visible layers. I tried to find the differences between the earlier scripts, but unfortunately nothing works for me. Greetings Anna

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
LEGEND ,
Sep 06, 2022 Sep 06, 2022

Copy link to clipboard

Copied

You would need to add code to test for layer type and hidden attributes, and check for duplicates. This gets into intermediate to advanced scripting.

Understand that this forum is not intended to be a "write a script for me" resource, you may get that in some cases (I have written scripts specifically to answer a post) but it can be time-consuming and difficult. If this is a real need, check someplace like ps-scripts.com and see if you can hire a developer.

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 ,
May 29, 2023 May 29, 2023

Copy link to clipboard

Copied

Hi @jazz-y , is there a way to skip the Hue/Saturation or any other filter layers from the list, because they are getting added too?

Thanks,

Mukul

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
Guide ,
May 29, 2023 May 29, 2023

Copy link to clipboard

Copied

quote

or any other filter layers from the list

By @chandubhau

Please use Photoshop terminology. I can't understand what exactly you are talking about.

This version ignores all adjustment layers:

 

#target photoshop
var s2t = stringIDToTypeID;
separator = ';';
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('json'));
r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));
eval('var layersCollection = ' + executeActionGet(r).getString(p).replace(/\\/g, ''));
var needToProcess = collectAdjustmentLayers(layersCollection.layers)
var f = new File('~/Desktop' + '/' + 'layerList.txt');
f.open('w');
f.encoding = 'UTF-8';
f.write(needToProcess.join(separator));
f.close();
function collectAdjustmentLayers(layersObject, collectedLayers, uniqueNames) {
    collectedLayers = collectedLayers ? collectedLayers : [];
    uniqueNames = uniqueNames ? uniqueNames : {};
    for (var i = 0; i < layersObject.length; i++) {
        var cur = layersObject[i];
        if (!uniqueNames[cur.name] && cur.visible && cur.type != 'adjustmentLayer') {
            uniqueNames[cur.name] = true;
            collectedLayers.push(cur.name)
        }
        if (cur.layers) collectAdjustmentLayers(cur.layers, collectedLayers, uniqueNames)
    }
    return collectedLayers;
}

 

 

 
 

 

 

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 ,
May 29, 2023 May 29, 2023

Copy link to clipboard

Copied

Ok thanks. I was referring to old code by mistake.

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 ,
Jul 05, 2023 Jul 05, 2023

Copy link to clipboard

Copied

Hi guys, everytime I try any of these scripts Photoshop 2023 throws at me Error 8: Syntax Error.

Is there something I am doing wrong or does Photoshop 2023 not like these scripts anymore?

Thanks!

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 ,
Jul 05, 2023 Jul 05, 2023

Copy link to clipboard

Copied

Hi there, when I try to run this script in Photoshop 2023 I keep getting Error 8: Syntax Error.

Am I doing something wrong or is this script not compatible with Photoshop 2023?

Thanks!

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 ,
Aug 12, 2023 Aug 12, 2023

Copy link to clipboard

Copied

LATEST

Screenshot please.

 

Does it mention RTF in the error? Did you save it as RTF when it should be saved as plain TXT?

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 ,
May 13, 2017 May 13, 2017

Copy link to clipboard

Copied

This is also possible with ExifTool using the following command:

exiftool -Photoshop:LayerNames PATH-TO-FILE-or-FOLDER

Which would output the following (which may be a little cryptic, see the screenshot below for a visual):

Color Fill 1, </Layer group>, Layer 0, Layer 1, Layer 2, Layer 3, Group 1, Layer 4, Invert 1

layers.png

For an Adobe Illustrator .AI file, the command would be:

exiftool -a -XMP-egLayL:LayersName PATH-TO-FILE-or-FOLDER

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 ,
May 28, 2023 May 28, 2023

Copy link to clipboard

Copied

Hi. is there a way to skip the Hue/Saturation layers from the list, because they are getting added too?

Thanks,

Mukul

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 ,
May 29, 2023 May 29, 2023

Copy link to clipboard

Copied

quote

Hi. is there a way to skip the Hue/Saturation layers from the list, because they are getting added too?

Thanks,

Mukul


By @chandubhau

 

What method are you using, the one from @jazz-y or another one?

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