Skip to main content
Participant
January 18, 2018
Question

Change layer names so lowercase

  • January 18, 2018
  • 2 replies
  • 804 views

Hey guys,

posting for the first time and i dont know any sort of scripting so would be helpful if anyone can help.

I want to change each and every layer names to complete lower case. Eg : Picture_Large.png >> picture_large.png

There around 1000 layers so i hope you understand the difficulty to change it manually. I found a script but it changes it to uppercase and only changes groups and not all layers. Here

Plz help

This topic has been closed for replies.

2 replies

Legend
January 18, 2018

aaaa()

function aaaa()

    {  

    try {

        var i = get_layer_count();

        var end = 1;   

        var ret_ok = true; 

        while (i >= end && process_layer(i)) { --i; }

        return ret_ok;

        function get_layer_count()

            {

            try

                {

                var r = new ActionReference();

                r.putEnumerated( charIDToTypeID( "Lyr " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );

       

                var ret, n;

       

                try { ret = executeActionGet(r);                       } catch (e) { alert(e); ret_ok = false; return 0; }

                try { n   = ret.getInteger(stringIDToTypeID("count")); } catch (e) { alert(e); ret_ok = false; return 0; }

                r = null;

                ret = null;

                try { app.activeDocument.backgroundLayer; } catch(e) { return n; }

       

                return n-1;

                }

            catch (e) { alert(e); ret_ok = false; return 0; }

            }

        function process_layer(n)

            {  

            try {

                var r = new ActionReference();

                r.putIndex( charIDToTypeID( "Lyr " ), n);

       

                var ret, s;

                try { ret = executeActionGet(r); } catch(e)  { alert(e); ret_ok = false; return false; }

                var name = ret.getString(stringIDToTypeID("name"));

                switch (ret.getEnumerationValue(stringIDToTypeID("layerSection")))

                    {

                    case stringIDToTypeID("layerSectionEnd"):

                        break;

                    default:

                        var name = ret.getString(stringIDToTypeID("name"));

                        var name1 = name.toLowerCase();

                        if (name1 == name) break;

                        var d1 = new ActionDescriptor();

                        d1.putReference( charIDToTypeID( "null" ), r );

                        executeAction( charIDToTypeID( "slct" ), d1, DialogModes.NO ); // because of the bug at least in CS6 - CC2108

                                                                                       // can't set layer name if layer is not active

                        ret = new ActionDescriptor();

                        ret.putString(stringIDToTypeID("name"), name1);   

                        d1.putObject( charIDToTypeID( "T   " ), charIDToTypeID( "Lyr " ), ret );

                        executeAction( charIDToTypeID( "setd" ), d1, DialogModes.NO );

                        break; 

                    }  

                ret = null;

                return true;

                }

            catch (e) { alert(e); ret_ok = false; return false; }

            }

        }

    catch (e) { alert(e); }

    }

Participant
January 18, 2018

It worked!!!

Thank you so much

Geppetto Luis
Legend
January 18, 2018

see if this is right for you

// written by Lukasz Wieczorek at http://lukasz.io

// Please do not remove this and give credit if you repost. Thanks!

var layerLength = app.activeDocument.layers.length;

var docRef  = app.activeDocument;

for(i = 0; i < layerLength; i++){

   docRef.activeLayer = docRef.layers

   var myName = app.activeDocument.activeLayer.name;

    var newName = myName.toLowerCase();

    docRef.activeLayer.name = newName;

}

Participant
January 18, 2018

ok so i ran your script and this what happened:

1. Only the artboard case changed to lowercase

2. All other unselected or hidden layers were affected.

3. Didnt changed the layers that were nested inside the groups.