Skip to main content
dublove
Legend
May 18, 2026 4:32 PM UTC
Answered

How to simultaneously modify layer names and colors?

make a judgment first:

If the document only has one layer and the layer name is not aa.

I will rename this layer to "aa" and change the color to red
 

 

    rob day
    rob dayCorrect answer
    Community Expert
    May 18, 2026 4:40 PM UTC
    var d = app.activeDocument;
    if (d.layers.length == 1) {
    d.layers[0].properties = {name:"aa", layerColor:UIColors.RED}
    }

     

    8 replies

    dublove
    dubloveAuthor
    Legend
    May 18, 2026 11:39 PM UTC

    Hi ​@rob day 

    How to determine if aa is at the lowest level (Location Options. AT-END)

    Thank you very much.

     

    Translate
    rob day
    Community Expert
    Community Expert
    May 19, 2026 12:20 PM UTC

    The layer index goes from top to bottom, so the bottom layer is d.layers[d.layers.length-1]. You would use Location Options if you want to move a layer

     

    var d = app.activeDocument;
    //Bottom layer name
    alert(d.layers[d.layers.length-1].name)
    //Top layer name
    alert(d.layers[0].name)

     

    Translate
    rob day
    Community Expert
    rob dayCommunity ExpertCorrect answer
    Community Expert
    May 18, 2026 4:40 PM UTC
    var d = app.activeDocument;
    if (d.layers.length == 1) {
    d.layers[0].properties = {name:"aa", layerColor:UIColors.RED}
    }

     

    Translate