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?

Try this. Just select the layers you want 'copy' removed from and run this script.
if( app.documents.length > 0 ){
app.activeDocument.suspendHistory('Rename selected layers','removeCopyFromSelectedLayersNames()');
function removeCopyFromLayerName(){
     if( getSelectedLayersIdx().length > 1 ){
          var selectedLayers = getSelectedLayersIdx();
          makeActiveByIndex( selectedLayers[0], false );
   var startLoop = Number( !hasBackground() );
   var endLoop = getNumberOfLayer() + 1;
   for( var l = startLoop;l < endLoop; l++){
        while( !isValidActiveLayer( l ) ) {
            l++;
          var oldName =  getLayerNameByIndex( l );
          var newName = oldName.replace(/\scopy\s?\d*$/i,'');
          putLayerNameByIndex( l, newName )
     if( selectedLayers != undefined ) makeActiveByIndex( selectedLayers, false );
function removeCopyFromSelectedLayersNames(){
     var selectedLayers = getSelectedLayersIdx();
     for( var l = 0;l < selectedLayers.length; l++){
          var oldName =  getLayerNameByIndex( selectedLayers[ l ] );
          var newName = oldName.replace(/\scopy.*$/i,'');
          makeActiveByIndex( selectedLayers[ l ], false );
          putLayerNameByIndex( selectedLayers[ l ], newName )
     makeActiveByIndex( selectedLayers, false );
function getNumberOfLayer(){
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID('Dcmn'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
var desc = executeActionGet(ref);
var numberOfLayer = desc.getInteger(charIDToTypeID('NmbL'));
return numberOfLayer;
function getLayerNameByIndex( idx ) {
    var ref = new ActionReference();
    ref.putProperty( charIDToTypeID('Prpr') , charIDToTypeID( 'Nm  ' ));
    ref.putIndex( charIDToTypeID( 'Lyr ' ), idx );
    return executeActionGet(ref).getString(charIDToTypeID( 'Nm  ' ));;
function putLayerNameByIndex( idx, name ) {
     if( idx == 0 ) return;
    var desc = new ActionDescriptor();
        var ref = new ActionReference();
        ref.putIndex( charIDToTypeID( 'Lyr ' ), idx );
    desc.putReference( charIDToTypeID('null'), ref );
        var nameDesc = new ActionDescriptor();
        nameDesc.putString( charIDToTypeID('Nm  '), name );
    desc.putObject( charIDToTypeID('T   '), charIDToTypeID('Lyr '), nameDesc );
    executeAction( charIDToTypeID('setd'), desc, DialogModes.NO );
function getActiveLayerIndex() {
     var ref = new ActionReference();
     ref.putProperty( 1349677170 , 1232366921 );
     ref.putEnumerated( 1283027488, 1332896878, 1416783732 );
     var res = executeActionGet(ref).getInteger( 1232366921 )
                                                       - Number( hasBackground() );
     return res;  
function isValidActiveLayer( idx ) {
     var propName = stringIDToTypeID( 'layerSection' );
     var ref = new ActionReference();
     ref.putProperty( 1349677170 , propName);
     ref.putIndex( 1283027488, idx );
     var desc =  executeActionGet( ref );
     var type = desc.getEnumerationValue( propName );
     var res = typeIDToStringID( type );
     return res == 'layerSectionEnd' ? false:true;
function hasBackground(){
    var res = undefined;
    try{
        var ref = new ActionReference();
        ref.putProperty( 1349677170 , 1315774496);
        ref.putIndex( 1283027488, 0 );
        executeActionGet(ref).getString(1315774496 );;
        res = true;
    }catch(e){ res = false}
    return res;
function getSelectedLayersIdx(){
     var selectedLayers = new Array;
     var ref = new ActionReference();
     ref.putEnumerated( charIDToTypeID('Dcmn'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
     var desc = executeActionGet(ref);
     if( desc.hasKey( stringIDToTypeID( 'targetLayers' ) ) ){
          desc = desc.getList( stringIDToTypeID( 'targetLayers' ));
          var c = desc.count
          var selectedLayers = new Array();
          for(var i=0;i<c;i++){
               selectedLayers.push(  desc.getReference( i ).getIndex());
     }else{
          var ref = new ActionReference();
          ref.putProperty( charIDToTypeID('Prpr') , charIDToTypeID( 'ItmI' ));
          ref.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
          selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( 'ItmI' )));
     return selectedLayers;
function makeActiveByIndex( idx, visible ){
     if( idx.constructor != Array ) idx = [ idx ];
     for( var i = 0; i < idx.length; i++ ){
          var desc = new ActionDescriptor();
          var ref = new ActionReference();
          ref.putIndex(charIDToTypeID( 'Lyr ' ), idx[i])
          desc.putReference( charIDToTypeID( 'null' ), ref );
          if( i > 0 ) {
               var idselectionModifier = stringIDToTypeID( 'selectionModifier' );
               var idselectionModifierType = stringIDToTypeID( 'selectionModifierType' );
               var idaddToSelection = stringIDToTypeID( 'addToSelection' );
               desc.putEnumerated( idselectionModifier, idselectionModifierType, idaddToSelection );
          desc.putBoolean( charIDToTypeID( 'MkVs' ), visible );
          executeAction( charIDToTypeID( 'slct' ), desc, DialogModes.NO );

Similar Messages

  • Script to batch rename/number layers in Illustrator CS6

    Is there a script that I can use in Illustrator to batch rename all sub-layers? I would also like to be able to add sequential numbers to each layer too. I saw an older post that contained a script to do this but it seemed outdated and doesn't work on CS6. Here it is for reference, maybe someone can modify it to work for CS6?
    ////START SCRIPT////
    docRef=app.activeDocument;
    topLayers=docRef.layers;
    for(i=0;i<topLayers.length;i++){
    var currLayer=topLayers[i];
    var newNum=i+1;
    currLayer.name="Layer "+newNum;
    subLayers=topLayers[i].layers;
    for(j=0;j<subLayers.length;j++){
      var currSubLayer=subLayers[j];
      var newSubNum=j+1;
      currSubLayer.name="Layer "+ newNum+"."+newSubNum;
      subSubLayers=subLayers[j].layers;
       for(k=0;k<subSubLayers.length;k++){
        var currSubSubLayer=subSubLayers[k];
        var newSubSubNum=k+1;
        currSubSubLayer.name="Layer "+ newNum+"."+newSubNum+"."+newSubSubNum;
    ////END SCRIPT////

    You got me to investigate if other files and layer structures work, and I found one that partially worked. It stopped working after renaming the first top layer and sub-layers within that.
    Here's what kind of worked:
    before: after:
    Here's the structure that I ultimately want to edit and rename. They are the end levels, sub-sub-sub layers. I want all of them to be renamed to "applyColor1" "applyColor2" etc.

  • Renumber/Batch rename layers

    Hi, is there a quick way how to renumber or batch rename all layers in a file so they would be named in consequent numbers? Doesn't have to start from exact number, I was wondering if maybe there is some sort of script that would help me with that? Thanks a lot

    This thread is kind of old, but I found JET's script to be extremely useful, and like Steven, I also needed it to start from the bottom layer.  So I updated it a little.
    Set "fromTop" to "true" if you want it to name the top-most layer #1.
    Set "fromTop" to "false" if you want the bottom-most layer to be #1.
    ////START SCRIPT////
    #target Illustrator
    var docRef = app.activeDocument;
    var fromTop = true;                 
            // if true,  the top layer will be #1
            // if false, the bottom layer will #1
    renumberLayers(fromTop);
    function renumberLayers(fromTop){
        var topLayers = docRef.layers;
        for(i=0; i<topLayers.length; i++){
            var currLayer = topLayers[i];
            if(fromTop) var newNum = i + 1;
            else var newNum = topLayers.length - i;
            currLayer.name="Layer "+newNum;
            subLayers= topLayers[i].layers;
            for(j=0; j<subLayers.length; j++){
                var currSubLayer = subLayers[j];
                var newSubNum = subLayers.length - j;
                currSubLayer.name="Layer "+ newNum+"."+newSubNum;
                subSubLayers=subLayers[j].layers;
                for(k=0; k<subSubLayers.length; k++){
                    var currSubSubLayer = subSubLayers[k];
                    var newSubSubNum = subSubLayers.length - k;
                    currSubSubLayer.name="Layer "+ newNum+"."+newSubNum+"."+newSubSubNum;
    ////END SCRIPT////

  • Apple script to batch rename files by deleting tags on front and back of the file name

    Hi, I'm trying to rename a couple thousand files from their current format:  "01074_Something Of A Dreamer_Mary-Chapin Carpenter.lrc"
                                                                                                                           "01075_Where Did We Go Right_Lacy J. Dalton.lrc"
                                                                                                                           "01076_Everybody's Reaching Out_Crystal Gayle.lrc"
                                                                                                         To simply:  "Something Of A Dreamer.lrc"
                                                                                                                           "Where Did We Go Right.lrc"
                                                                                                                           "Everybody's Reaching Out.lrc"
    I just want to delete the number tag on the front and the artist name at the end for all of the files.  I imagine a Script to do this wouldn't be too hard to write, something along the lines of read file name after the first '_' character it reads until it reads a second '_' character and rename the file to the string it reads between those two underscores with .lrc at the end.
    Unfortunately I know nothing about Apple Script other than it seems like the thing I would need to automate this process based on my limited google searches.  If someone could help me out with some advice on how to go about making this script or obviously if you simply have and/or can quickly write a script to do this it would be greatly appreciated!

    Here:
    tell application "Finder"
    repeat with this_file in (get files of window 1)
    set the_name to name of this_file
    set temp_name to items ((offset of "_" in the_name) + 1) thru -1 of the_name as string
    set temp_name to (items 1 thru ((offset of "_" in temp_name) - 1) of temp_name as string) & items -4 thru -1 of the_name as string
    set name of this_file to temp_name
    end repeat
    end tell
    (123647)

  • A script to batch rename and relink images?

    Hello, everyone!
    First of all, I did search for this before asking and found many similar scripts for this, but as I don't know how to make or edit scripts, I couldn't use them...
    I work at a company that makes school books. Each InDesign file we make can have hundreds of images, of varied extensions (.ai, .eps, .tif, .psd).
    We now need to rename those images to a default naming system we defined. This is taking hours, even days to do manually.
    Those images currently have varied names, so we'd need to ignore what's there, we just need a configurable prefix (like "EF6_ESP_C1_"), then a 4-digit number starting at 0001 and numbering the rest (if there's say a .tif and then a .ai, it'd have to be 0001.tif and 0002.ai), then the extension it already had.
    Preferably, but not required, if it could read that the image already had an "EQ" in the file name, it could rename them to another prefix and count those separately from 0001, as we work Equation images separately, but if this can't be done or is too difficult to do, then just have them named and numbered with the others.
    Could anyone be so kind as to help me with this? Thank you very much!

    Try this,
    var doc = app.activeDocument,
        links = doc.allGraphics, count = 1, eqcount = 1, a = "0000";
    for(var i=links.length-1;i>=0;i--)
            if(links[i].itemLink.name.match(/^EQ.+/))
                    var ext = links[i].itemLink.name.substr(links[i].itemLink.name.lastIndexOf(".")),
                        old = File(links[i].itemLink.filePath),
                        eqnum = (eqcount++).toString(),
                        newname = "EQ_EF6_ESP_C1_" + a.substring(0, a.length - eqnum.length) + eqnum + ext;
                    old.rename(newname);
                    links[i].itemLink.relink(File(old.toString().replace(links[i].itemLink.name,newname)))
            else
                    var ext = links[i].itemLink.name.substr(links[i].itemLink.name.lastIndexOf(".")),
                        old = File(links[i].itemLink.filePath),
                        num = (count++).toString(),
                        newname = "EF6_ESP_C1_" + a.substring(0, a.length - num.length) + num + ext
                    old.rename(newname);
                    links[i].itemLink.relink(File(old.toString().replace(links[i].itemLink.name,newname)))
    Please note:It is not reversible.
    Regards,
    Chinna

  • Script to rename layers comps batch?

    Does anyone know any script to rename batch comps layers in a sequential numbering? For example: layerComps01, layerComps02, layerComps03 ...

    // 2014, use it at your own risk;
    #target photoshop
    if (app.documents.length > 0) {
    var myDocument = app.activeDocument;
    for (var m = 0; m < myDocument.layerComps.length; m++) {
    myDocument.layerComps[m].name = "comp"+bufferNumberWithZeros(m+1, 2)
    ////// buffer number with zeros //////
    function bufferNumberWithZeros (number, places) {
      var theNumberString = String(number);
      for (var o = 0; o < (places - String(number).length); o++) {
      theNumberString = String("0" + theNumberString)
      return theNumberString

  • Batch Rename PSD Layers to File Name Script?

    Hello,
    I just recieved several thousand .PSD files for a job containing a single layer (named "Layer 1") on a transparent background. I'm trying to find a way to batch rename the layer in each of these files as the file name, sans the file extension. Is there a script out there that can do this for me? Forgive me, I am not too hip with scripts.
    Windows 7 PC, CS6
    Thank you!

    Save the line below into a plain text file and give it the .jsx extension.
    app.activeDocument.activeLayer.name = decodeURI(app.activeDocument.name).match(/(.*)(\.[^\.]+)/)[1];
    Then create an action that runs that script. Then run File-Automate-Batch using that action.

  • Batch rename selected layers

    I'm trying to find a script that can help batch rename/renumber a group of selected layers.
    So far I've been able to find a script that renames every single layer in a Photoshop document (overkill). Or there's the CS6 Tab rename trick (too slow).
    I routintely export PSDs from Illustrator for use in After Effects. But in Photoshop, I'll get a couple hundred layers named <path> or <path> + <path> or <group>. Renaming by hand is out of the question. But I don't want to rename every layer the same.
    Any suggestions?

    I wrote one for you here...
    http://www.retouchpro.com/forums/photoshop-scripting/23234-script-find-replace-text-layer- names.html

  • Script: rename layers?

    Hi, is there a quick way how to renumber or batch rename all layers in a file so they would be named in consequent numbers? Doesn't have to start from exact number, I was wondering if maybe there is some sort of script that would help me with that? Thanks Pavel

    Thank you for the script. It is very useful.
    Could you help me with one thing? If I want to add letters "ca" in front of the number, where should I add "ca" and how to do that?
    The present script is 1, 2, 3, 4... on each layer.
    I want the script to be ca1, ca2, ca3, ca4... on each layer.
    Please help me out.

  • How do I batch-rename objects/paths (not just layers)?

    Question from a complete n00b:
    I need to rename a large number of selected objects/paths. This is because I want to use another script that only works when my objects have the default name, "<Path>". So really, I just need to remove existing names of objects.
    This other script is here:
    http://kelsocartography.com/blog/?p=325
    Of course, I could manually remove names by double-clicking on objects in the layers palette and deleting the name, but that's no fun.
    I've found some great scripts for renaming layers, but nothing for non-layer objects.
    First, I'm trying to remove names from ALL objects in the document.  once that's working, I want to only remove names of selected objects.
    Here's my very simple non-working javascript - (the whole thing):
    app.activeDocument.pageItem.name = "";
    my test Ai file is also really basic: a few rectangles, some of which have been named in the layers palette.
    When I run this, I get:
    Error 21: undefined is not and object.
    Line: 1
    ->     app.activeDocument.pageItem.name = "";
    I've tried a number of other approaches, and either get "undefined is not an object" or nothing happens. 
    pageItem has "name" as a writable property, so I think it's what to use, but I really don't know what I'm doing - help!
    I'd also happy to use actions, but I'm stuck on that too.

    Thanks!!
    Here's my final script:
    ////START SCRIPT////
    //how to use: select objects that you want to rename, then run script
    //note - new name may not display until you unselect objects
    var docRef = activeDocument;
    for (var i=0; i < docRef.pageItems.length; i++)
           if (docRef.pageItems[i].selected == true)
                   docRef.pageItems[i].name = "";
    ////END SCRIPT////
    currently, it renames with no text.  In other words, it removes existing names.
    One thing that was messing me up was that new names are not immediately displayed - you have to unselect your selected objects before names in the layers palette refresh.

  • HELP! Need a script for renaming layers

    Hi-
    I've got an Illustrator CS6 document that has 500+ layers with individual words on them (a word cloud).  I'm needing to animate this in AE.  When I "Release to Layers (Sequence)", all of the layers become Layer 1, Layer 2, etc.  Is there a script that will rename all of those layers to be the text inside them? 
    i.e. Layer 1 has the word "Pencil" as a sub-layer, editable text.. I need to rename the Top-Layer Layer 1 to "Pencil".  I'm hoping there is a script that can do this so I don't have to manually rename all of the layers.
    I have found this script:
    var idoc = app.activeDocument;
    var ilayer = idoc.activeLayer;
    for (i=0; i<ilayer.layers.length; i++) {
        var isublayer = ilayer.layers[i];
        isublayer.name = isublayer.pageItems[0].name;
    But is doesn't seem to do what I need.
    Any help would be greatly appreciated!
    Thanks,
    -Mark

    Hi Carlos-
    Here is part of my layers pannel before Releasing to Layers:
    Here is part of my layers pannel after Releasing to Layers:
    So I want Layer 6 to be "Hideaway Backpack Straps" without having to rename it manually.
    Any help would be great!
    Thanks
    Mark

  • How do I remove a number sequence using batch rename

    Hi
    I know I've done this in the past but cannot seem to work it out today.
    I have a series of images "_####_[layercompName].png".  I would like to remove the underscores and numbers.  The underscores removal is easy, but how do I remove the numbers (####) when they are different for each filename?  I would like the end result to be [layercompName].png
    The reason I have these filenames in the first place is that I have run the photoshop script "layer comps to files", and this adds a number sequence prefix.  I have tried to alter the script following various instructions I've found from trawling the internet (this one included How do you remove the number sequence when exporting layer comps to files? CS6. Windows 8.) but without any luck.  So now I'm resorting to batch renaming in Bridge.
    Thanks!

    Here you go, taken straight from: DesignEasy: How to Remove Sequence Numbers and Empty Spaces When Exporting Layers and Layer Comps
    Run Adobe Bridge and navigate to the folder with exported files.
    Select all files which have sequence numbers.
    Go to Tools > Batch Rename.
    Choose: String Substitution from the first drop-down list in New Filenamessection. From the second drop-down choose: Original Filename. In the Find: text field type: _\d{4}_ (underscore, backslash, letter d, open bracket, number four, closed bracket, underscore). Leave Replace with: text field blank. Ensure that you have Replace All and Use Regular Expression checked as shown on the screenshot below.
    Click on the Preview button in the top right corner and ensure that files will be renamed as you want.
    Click on Rename button and you are done.
    In case you are first time doing this and you still have doubts if everything will work as expected, check Copy to other folder option when renaming files. This option is located near the top left corner under: Destination Folder.
    Another thing I want to mention is to remove everything that you have below String Substitution options. In case you see additional renaming options just click on minus (-) sign on the right side to remove them.
    How to remove/substitute empty spaces in the file name using Adobe Bridge
    It is pretty similar process. The only difference is that you should type: \s (backslash followed with letter s) in the Find: text field. You can leave Replace with: text field blank or to type underscore.

  • Adobe Bridge CC: Batch Rename using any metadata field

    How can I add certain Metadata fields to the pull down menu in the batch rename function?
    I need to do a batch rename of files, but using metadata fields that are not available as an option on the pull down menu.
    Hoping to use any or all of these:
    Audio : Artist, Album, Genre
    IPTC Core : Description, Keywords, etc..

    I don't think there is any way in which you can add to the built-in functions…
    Unless this is actually provided by one of the Adobe start-up scripts… ( I've not see it when digging about )
    You would probably need a scripted solution that can give you drop down menu of the extra options you want.

  • Adobe Bridge CC Batch Rename and File Extensions

    I use Adobe Bridge CC on my macbook pro that is running OS X 10.8.5  When I batch rename files within Bridge it automatically drops the file extension. I am able to add the extension within the naming process but would prefer if it simply defaulted to the existing extension of the files being renamed. On occasion it does do this and then the next time it is gone. What am I doing wrong?

    I don't think there is any way in which you can add to the built-in functions…
    Unless this is actually provided by one of the Adobe start-up scripts… ( I've not see it when digging about )
    You would probably need a scripted solution that can give you drop down menu of the extra options you want.

  • Batch rename files preserving the original file name in metadata

    How can I batch rename files while preserving the original file name in metadata? (Don't want the old file name as part of the new file name)
    (Adobe CS Bridge can do this with some success, but I don't want to be dependant on this software. Results are inconsistent.)

    With a simple terminal script. More details needed, though.

Maybe you are looking for

  • Flash content will not display with Player: 10.3.183.7

    Hello, I helped to design a website last year in Flash based off a template purchased from myflashxml.com.  Up until the latest version of flash 10.3, all seemed to work ok.  As soon as upgrading to 10.3, we see the shift up to the left on the intro

  • IPod won't mount on desktop/in iTunes...updater useless

    I have a second generation iPod (scroll wheel/row of 4 buttons), and iTunes 6.0.4 running on a dp G4 500 with Mac OS 10.2.8. Suddenly my iPod won't appear on the desktop or in iTunes when I plug it into the dock. I've tried different FW ports, etc. a

  • How do I know which AirPort base station I am connected to?

    I have an AirPort network which consists of a Time Capsule and 2 AirPort Expresses connected in 'extended' mode. I want to test each of the AirPort Express units to ensure that they are doing what they should be (i.e. extending my network). However,

  • MIRO copy text

    Hi everybody, In the miro transaction, I filled the text field of the tab Basic data. I would like to copy this text in Header Text fields of the tab Details and in the text field of the tab PO reference. I made a search user-exit and badi to use by

  • Trash Wont Finish Emptying

    I was emptying my trash (securely, if that makes a difference), and since last night it's been stuck at "Items to Delete: 0" but when I click the button to cancel it, nothing happens. Anything I can do about it?