Skip to main content
Participant
February 13, 2008
Answered

PS3 script to batch rename layers

Sometimes, I make copies of layers (for example: copy little diamonds to align into a shape of the letter M). Each time I "alt+drag" the content in that layer (to make a copy of it), PS makes a copy and then appends the name of the layer to something like "diamond copy 3". After making a ton of copies (and because I'm anal about having actual names for each layer), I want each layer to read "diamond". Instead of manually renaming all these layers, is there a way to highlight the affected layers and choose to rename all layers according to what you want?
This topic is closed to new replies. Start a new post to keep the conversation going.
Anshul_Saini
Anshul_SainiCorrect answer
Community Manager
October 16, 2026

Hi everyone,

For anyone who comes across this thread looking for a solution in a current version of Photoshop, there’s now a native option you can try: Layer Cleanup.

In the Layers panel, select the Layer Cleanup icon, then choose Rename layers. You can apply it to either the selected layers or the Entire document. Layer Cleanup can also delete empty layers so that both cleanup operations can be handled from the same dialog.
Cleanup layers dialog box in Adobe Photoshop on desktop with options to delete empty layers, rename layers, and apply changes to selected layers.

Unlike the scripts shared earlier in this thread, which primarily remove suffixes such as “copy” or “copy 3” from existing layer names, Layer Cleanup can assign descriptive names based on each layer's actual content. This can be especially useful when a document contains many duplicated or generically named layers.

If you’re using a current version of Photoshop, give Layer Cleanup a try and let us know how it works for your workflow.

Best,
Anshul Saini

22 replies

Participant
February 29, 2008
Thanks for sharing... now, what do I do with this information?
Translate
MarkWalsh
Inspiring
February 28, 2008
You're in luck. I just finished writing this yesterday. :)

This will remove " copy", " copy 1"... etc from all open files. Let me know how it works out for you.

///////////////////////////////////////////////////////////////////////////////
// Script Name: RenameLayers.jsx
// Version: 1.0
// Date: 2/27/08
// Usage: Removes 'copy 1, copy 2, etc' from name of all layers
///////////////////////////////////////////////////////////////////////////////

#target photoshop
//$.localize = true;
var displayDialogMode = app.displayDialogs;

app.bringToFront();
app.bringToFront();
app.displayDialogs = DialogModes.NO;

processObjects(app.documents, processDocument,function () {alert("You have no documents open")})
app.displayDialogs = displayDialogMode;

///////////////////////////////////////////////////////////////////////////////
// Function: processObjects
// Usage: Runs theMainFunction on every object in list theObjects
// Input: List of objects (documents, layers, etc.), Function to run on each object, Function to run on parent if there are no object
// Return: value returned from function used
///////////////////////////////////////////////////////////////////////////////
function processObjects(theObjects, theMainFunction, theAlternateFunction) {
var returnValue = null;
if (theObjects.length ==0) {
if (!(theAlternateFunction == undefined) && !(theAlternateFunction == null) && !(theAlternateFunction == "")) {
returnValue = theAlternateFunction (theObjects.parent);
}
} else {
if (!(theMainFunction == undefined) && !(theMainFunction == null) && !(theMainFunction == "")) {
for (var i = theObjects.length -1; i> -1; i--) {
returnValue += theMainFunction (theObjects, i);
}
}
}
return returnValue;
}

///////////////////////////////////////////////////////////////////////////////
// Function: processDocument
// Usage: Processes layers of document with 'processLayer' function
// Input: Document object, Document object index
// Return: none
///////////////////////////////////////////////////////////////////////////////
function processDocument(objectRef, i) {
app.activeDocument = objectRef
processObjects(objectRef.layers, processLayer, null);
}

///////////////////////////////////////////////////////////////////////////////
// Function: processLayer
// Usage: Removes 'copy' from layer name (processes Layer Set contents)
// Input: Layer object, Layer Object index
// Return: none
///////////////////////////////////////////////////////////////////////////////
function processLayer(objectRef, i) {
if (objectRef.typename == 'LayerSet') {
var layerCount = processObjects(objectRef.layers, processLayer);
}
renameLayer(objectRef)
return 0
}

///////////////////////////////////////////////////////////////////////////////
// Function: renameLayer
// Usage: Removes 'copy' from layer name (processes Layer Set contents)
// Input: Layer object, Layer Object index
// Return: none
///////////////////////////////////////////////////////////////////////////////
function renameLayer(objectRef) {
var theRegEx = new RegExp(/^(.*)(copy(\s(\d)+)*)+$/)
if (theRegEx.test(objectRef.name)) {
var indexNumber = 0

indexnumber = objectRef.name.indexOf(" copy")
objectRef.name = objectRef.name.substr(0,indexnumber)
}
return 0
}
Translate