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

Similar Messages

  • Batch renaming and relinking in InDesign CS4

    Is there a plug-in available for InDesign that will batch rename and relink placed images?
    In Quark, I used Badia Link Renamer which worked perfectly but it's not available for InDesign. (Was told they hope to have it incorporated into BigPicture for CS5.)
    Is there something similar currently available for InDesign?
    Essentially I need it to rename and relink files with random names to structured names such as:
    001_Cust_000123456789_art_r1.tif
    (I love that Bridge does batch renaming but then I have to manually update links in InDesign which is extremely time-consuming. I've also manually renamed/relinked files individually with Adobe Dialogue but it doesn't seem to be part of CS4.)
    Any help or suggestions would be greatly appreciated! Been looking for something for months.
    Thanks!

    Here is my last version of the script, it deals with multiple instances of the same file.
    Kasyan
    var myDoc = app.activeDocument;
    var myAllLinks = myDoc.allGraphics;
    var myMultipleLinks = new Array();
    var myLinksCounter = 1;
    var myPrepend = prompt("Example: thebook_08765", "Job description", "Please enter job description");
    if (!myPrepend) exit();
    var response = confirm("Warning: You are about to rename all images linked to the foremost Indesign Document - proceed? Keep in mind - it is not reversible!", false, "Rename Links Script");
    if ( response == true )
         WriteToFile("\r--------------------- Script started -- " + GetDate() + " ---------------------\n\n");
         for ( k = 0; k < myAllLinks.length; k++ )
              var myLinkName = myAllLinks[k].itemLink.name;
         crearLabels();
         var myPages = myDoc.pages;
         // Pages
         for ( p = 0; p < myPages.length; p++ )
              var myPageNumber = pad000(myPages[p].name);
              var myLinks = myPages[p].allGraphics;
              var myASCII = 97;
              for ( k = myLinks.length - 1; k >= 0; k-- )
                   var myLink = myLinks[k].itemLink;
                   if (myLink.extractLabel("relinked") != "yes") {
                        var myOldLinkName = myLink.name;
                        var myLinkUsage = LinkUsage( myLink );
                        var myExtension = myOldLinkName.substr(myOldLinkName.lastIndexOf( "." ));
                        if (LinkUsage(myLink) == 1)
                             var myNewLinkName = myPrepend + myPageNumber + String.fromCharCode( myASCII ) + myExtension;
                             var myOldImageHDfile = new File( myLink.filePath );
                             var myRenameResult = myOldImageHDfile.rename( myNewLinkName );
                             if (myRenameResult)     {
                                  myLink.insertLabel("relinked", "yes");
                                  myLink.relink( myOldImageHDfile );
                                  try {
                                       myLink = myLink.update();
                                  catch(err) {}
                                  myASCII++;
                                  WriteToFile(((myLinksCounter < 10) ? (" " + myLinksCounter) : myLinksCounter) + " - " + myOldImageHDfile.name + " --> " + myNewLinkName + "\n");
                                  myLinksCounter++;
                             else {
                                  if (new File(myOldImageHDfile.parent + "/" + myNewLinkName + myExtension).exists) {
                                       WriteToFile("CAN'T RENAME LINK -- " + myOldImageHDfile.name + " to " + myNewLinkName + " because the file already exists\n");
                                  else {
                                       WriteToFile("CAN'T RENAME LINK -- " + myOldImageHDfile.name + "\n");
                        else {
                             if (!IsObjInArray(myLink, myMultipleLinks)) {
                                  myMultipleLinks.push(myLink);
         var myMasterSpreads = myDoc.masterSpreads;
         // Master spreads
         for ( m = 0; m < myMasterSpreads.length; m++ )
              var myMastSpr = myMasterSpreads[m];
              var myPageNumber = myMastSpr.name;
              var myPrefix = myMastSpr.namePrefix;
              var myLinks = myMastSpr.allGraphics;
              var myASCII = 97;
              for ( n = myLinks.length - 1; n >= 0; n-- )
                   var myLink = myLinks[n].itemLink;
                   if (myLink.extractLabel("relinked") != "yes") {
                        var myOldLinkName = myLink.name;
                        var myExtension = myOldLinkName.substr(myOldLinkName.lastIndexOf( "." ));
                        if (LinkUsage(myLink) == 1)
                             var myLinkLetter = (myLinks.length == 1) ? "" : String.fromCharCode( myASCII );
                             var myNewLinkName = myPrepend + '_master_' + myPrefix + myLinkLetter + myExtension;
                             var myOldImageHDfile = new File( myLink.filePath );
                             var myRenameResult = myOldImageHDfile.rename( myNewLinkName );
                             if (myRenameResult) {
                                  myLink.insertLabel("relinked", "yes");
                                  myLink.relink( myOldImageHDfile );
                                  try {
                                       myLink.update();
                                  catch(err) {}
                                  myASCII++;
                                  WriteToFile(((myLinksCounter < 10) ? (" " + myLinksCounter) : myLinksCounter) + " - " + myOldImageHDfile.name + " --> " + myNewLinkName + "\n");
                                  myLinksCounter++;
                             else     {
                                  if (new File(myOldImageHDfile.parent + "/" + myNewLinkName + myExtension).exists) {
                                       WriteToFile("CAN'T RENAME LINK -- " + myOldImageHDfile.name + " to " + myNewLinkName + " because the file already exists\n");
                                  else {
                                       WriteToFile("CAN'T RENAME LINK -- " + myOldImageHDfile.name + "\n");
                        else
                             if (!IsObjInArray(myLink, myMultipleLinks)) {
                                  myMultipleLinks.push(myLink);
         // Multiple images
         if (myMultipleLinks.length > 0) {
              for ( a = myMultipleLinks.length - 1; a >= 0; a-- )
                   processMultiUsedLinks(myMultipleLinks[a]);
         WriteToFile("\r--------------------- Script finished -- " + GetDate() + " ---------------------\r\r");
         if (myLinksCounter == 0) {
              alert("No links have been renamed", "Rename Links Script");
         if (myLinksCounter == 1) {
              alert("One link has been renamed", "Rename Links Script");
         else if (myLinksCounter > 1) {
              alert(myLinksCounter  + " links have been renamed", "Rename Links Script");
    //--------------------------------------------- Functions ------------------------------------------------
    // Check how many times the link was placed
    function LinkUsage(myLink) {
         var myLinksNumber = 0;
              for (var c =  0; c < myDoc.links.length; c++) {
              if (myLink.filePath == myDoc.links[c].filePath) {
                   myLinksNumber += 1;
         return myLinksNumber;
    // Relink the links placed more than once
    function processMultiUsedLinks(myLink) {
         var myExtension = myLink.name.substr(myLink.name.lastIndexOf( "." ));
         var myMultiUsedLink = new Array();
         var myAllLinks = myDoc.links;
         for (var d = 0; d < myAllLinks.length; d++)  {
              if (myAllLinks[d].filePath == myLink.filePath) {
                   myMultiUsedLink.push(myAllLinks[d]);
         try {
              myLink.show();
         catch(err) {}
         var myNewLinkName = prompt ("Enter a name for this image", GetFileNameOnly(myLink.name), "This image is placed " + myMultiUsedLink .length + " times");
         if (myNewLinkName) {
              if ( myNewLinkName + myExtension != myLink.name ) {
                   var myOldImageHDfile = new File( myLink.filePath );
                   var myRenameResult = myOldImageHDfile.rename( myNewLinkName + myExtension );
                   if (myRenameResult) {
                        myLink.insertLabel("relinked", "yes");
                        myLink.relink( myOldImageHDfile );
                        try {
                             myLink = myLink.update();
                        catch(err) {}
                        WriteToFile(((myLinksCounter < 10) ? (" " + myLinksCounter) : myLinksCounter) + " - " + myOldImageHDfile.name + " --> " + myNewLinkName + "\n");
                        myLinksCounter++;
                        for (f = myMultiUsedLink.length-1; f >= 0 ; f--)
                             var myCurrLink = myMultiUsedLink[f];
                             if ( myNewLinkName + myExtension != myCurrLink.name ) {
                                  myCurrLink.insertLabel("relinked", "yes");
                                  myCurrLink.relink( myOldImageHDfile );
                                  try {
                                       myCurrLink = myLink.update();
                                  catch(err) {}
                   else     {
                        if (new File(myOldImageHDfile.parent + "/" + myNewLinkName + myExtension).exists) {
                             WriteToFile("CAN'T RENAME LINK -- " + myOldImageHDfile.name + " to " + myNewLinkName + myExtension + " because the file already exists\n");
                        else {
                             WriteToFile("CAN'T RENAME LINK -- " + myOldImageHDfile.name + "\n");
         UpdateAllOutdatedLinks();
    // Clear labels in case this script has been already run on the current document
    function crearLabels() {
         for (var f =  0; f < myDoc.links.length; f++) {
              if (myDoc.links[f].extractLabel("relinked") != "") {
                   myDoc.links[f].insertLabel("relinked", "");
    function UpdateAllOutdatedLinks() {
         for(var myCounter = myDoc.links.length-1; myCounter >= 0; myCounter--){
              var myLink = myDoc.links[myCounter];
              if (myLink.status == LinkStatus.linkOutOfDate){
                   myLink.update();
    function pad000(myNumber) {
         if (myNumber >= 1 && myNumber <= 9) {
              x =  "0" + "0" + myNumber;
         } else if (myNumber >= 10 && myNumber <= 99) {
              x = "0" + myNumber;
         } else if (myNumber >= 100 && myNumber <= 999) {
              x = myNumber;
         return x;
    function GetFileNameOnly(myFileName) {
         var myString = "";
         var myResult = myFileName.lastIndexOf(".");
         if (myResult == -1) {
              myString = myFileName;
         else {
              myString = myFileName.substr(0, myResult);
         return myString;
    function IsObjInArray(myObj, myArray) {
         for (x in myArray) {
              if (myObj.filePath == myArray[x].filePath) {
                   return true;
         return false;
    function WriteToFile(myText) {
         myFile = new File("~/Desktop/Rename Links Script.txt");
         if ( myFile.exists ) {
              myFile.open("e");
              myFile.seek(0, 2);
         else {
              myFile.open("w");
         myFile.write(myText);
         myFile.close();
    function GetDate() {
         var myDate = new Date();
         if ((myDate.getYear() - 100) < 10) {
              var myYear = "0" + new String((myDate.getYear() - 100));
         } else {
              var myYear = new String ((myDate.getYear() - 100));
         var myDateString = (myDate.getMonth() + 1) + "/" + myDate.getDate() + "/" + myYear + " " + myDate.getHours() + ":" + myDate.getMinutes() + ":" + myDate.getSeconds();
         return myDateString;

  • I need to batch rename and relink files in indesign

    I have a whole bunch of files that I need to rename ( I need to add a prefix on to the front eg. a whole group of files called "plan.jpg" 01.jpg, 02.jpg, etc... need to now read ORD_plan.jpg, ORD_01.jpg, etc...) I can batch rename the files in adobe bridge, but I have to go in one by one and re-connect the links. Is there a script which can batch rename and relink all the files? 
    Thanks!

    This biterscripting script may possibly help. It takes two input arguments.
    directory - directory under which the .jpg files are located
    prefix - prefix which will be added to each file's name
    # Script RenameJpg.txt
    var str directory, prefix, list, filepath, name
    cd $directory
    find -n "*.jpg" > $list
    while ($list <> "")
    do
        lex "1" $list > $filepath ; stex -p "^/^l[" $filepath > $name
        set $name = $prefix+$name
        system copy ("\""+$filepath+"\"") ("\""+$name+"\"")
    done
    This is the way you would use it - copy and paste the script code into file C:/Scripts/RenameJpg.txt, then enter this command into biterscripting.
    script "C:/Scripts/RenameJpg.txt" directory("C:/test") prefix("ORD_")
    It will rename C:/test/plan.jpg to C:/test/ORD_plan.jpg, C:/test/01.jpg to C:/test/ORD_01.jpg, etc.
    Important: I am using the 'system copy' command so that files are copied instead of renamed. Once you are happy with the test, you can change that command to 'system rename'.
    Also, if the .jpg files are within subfolders of C:/test, change the 'find -n' to 'find -r -n'. -r means recursive = search in subfolders. Syntax for the find command at http://www.biterscripting.com/helppages/lf.html
    Message was edited by: Peter Spier to change 'path' to 'filepath' per post below
    Message was edited by: Peter Spier to change "perfix to "prefix"

  • Package batch renaming and relinking duplicates

    A plug-in/script available for InDesign to package some folders indd files into one folder with .indd, .pdf, .idml, links and fonts in folder, if images are duplicated between documents, rename with suffix "_1, _2, ....
    I need it to rename and relink files with random names to add suffix "_1, _2, _n number"  images are in .eps, .pdf, .psd, .jpg, etc. Names such as:
    design.tif      design_1.tif  
    design.eps    design_1.eps
    abcd.psd   adcd_1.psd
    abcd.psd   adcd_2.psd  
    abcd.psd   adcd_3.psd
    abcd.psd   adcd_4.psd
    design20.tif      design20_1.tif  
    design_14.eps    design_14_1.eps
    abcd.pdf   adcd_1.pdf
    abcd.jpg   adcd_2.jpg  
    Manually update links in InDesign, which is extremely time taking. I have found many scripts, but those are either keeping only one link when a package or changing one by one in each indesign documents and than package as usual.
    Any help or suggestions would be greatly appreciated.
    Thanks!

    Thank you for your great help. It is very useful  in future.
    It is doing 90% work of the package. It keeps link folder with one link, which is coming suppose in more than two documents.
    Same name images used between documents, with may be some changes,
    I need a script to rename and relink  duplicate files with random names to add suffix "_1, _2, _n number"  images are in .eps, .pdf, .psd, .jpg, etc., and package.

  • 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 and now files will not open

    i hope someone can help me. i moved some .dng files from an external drive to my mapbook pro using batch rename in bridge CS5. The files moved to my desktop ine, but now they will not open. When I try to open them  the digital convertor opens up. When I try to open them in photoshop it says it is a unrecognized format. They were fine ten minutes ago in bridge. does anyone have anything they can have me try? I am depserate to get these images printed up tonight and I don't have time to edit them again.

    You probably forgot to include the extension .dng or renamed with an extra dot (.) in the filename. Be surr to have only 1 dot with the three letter extension dng at the end (. dng)
    You can use Bridge for that again to rename and use the dng extension

  • Batch Renaming and renaming folders not working

    I have copied and pasted 500 RAW canon images from a 5D Mark III into a new folder on a Drobo 5d via firewire 800 card reader (from two 16Gb Extreme Pro Sandisk CF cards) - The drobo is connected via Thunderbolt. Both cards transferred well and I batch renamed the first 278 pictures. The first thing I noticed was that I could not chnage the folder name from Untitled folder to the new name that I wanted to call it. I tried to do this but nothing happened. I went into the folder on the drobo and batch renamed the first lot of images. There was no problem, everything worked fine. After I copied and pasted the second card ( I can not use photo downloader with file renaming with the firewire 800 card reader - something that I think is ridiculous), I tried to batch rename all the new images following on in file name from the first ones. I press Rename and then nothing happens..... I still can not change the folder either. I am running Mac OSx 10.7.4 and CS6.

    - The drobo is connected via Thunderbolt.
    Check this (long) thread and especially post 53 where Peter Britt Bailey had also found that changing Drobo Thunderbolt to USB connection solved his problems:
    http://forums.adobe.com/message/5357997#5357997
    ( I can not use photo downloader with file renaming with the firewire 800 card reader - something that I think is ridiculous),
    That is odd, I have owned a Lexar FW 800 card reader but this one died eventually and could not find a replacement until recently I found the DeLock FW 800 card reader.
    Never had nor have any trouble with those FW800 card readers when renaming my files using Photodownloader.
    Only the second option to back up the original to an other disk is not possible in Photodownloader.

  • 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.

  • Batch Rename and Restructure Folders and Pictures within

    Hello, I have been messing around with Automator trying to get Automator to batch rename my pictures. It seems that Automator is a little limited in renaming the way I would like to.
    I would like to rename all of my pictures to have a folder structure (I don't believe Automator can do this part for me) of:
    "Pictures/Nikon Transfer 2/Date Taken yyyy - dd- mm/DSC_xxxx"
    Currently, after trying one of the programs out, I have altered the filename over several of them to a mess of something like "2012-01-24-DSC_0295.JPG.JPG" where the folder structure  I was trying to achieve was put into the filename and the extension was added into the filename.
    I have tried several programs (freeware and open source) to achieve this to no avail. I would like to stay away from trail software and paid software.  If anyone knows of any Automator tricks or other free, non-trial programs that can do such a thing please let me know! It would be greatly appreciated. Thank you very much for any feedback! PSkilton

    There are several renamers on the appstore. I use one that is called "A Better Finder Rename", which for me is very good: you find the download button here:
    http://www.publicspace.net/ABetterFinderRename/troubleshooting.html
    It is not free but still cheap.

  • 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)

  • Irritating UI "bugs" when renaming and deleting images

    I have been using iPhoto for a couple of years now, and there are some minor glitches in the UI that simply frustrates the **** out of me in the new '08 version. Perhaps it's due to "wrong" usage, so please tell me if I can avoid them:
    Firstly, I'm often viewing and comparing my images in fullscreen when cleaning up a large batch of vacation photos, but when I apple+backspc. to delete an image, it jumps to the start of the Event instead of showing me the image before/after the one I deleted - WHY!? This is only in fullscreen view - if I space-view it goes to the next picture as expected?
    Secondly, there is apparently no shortcut for renaming an image, when viewing the thumbnails in an event or album. Numeric enter doesn't work (as ie. in iTunes), neither does (Windows) F2 or anything I could think of at least. Is there a shortcut that I just missed - please tell me!
    This could seem rather minor, but my library counts 5800+ images, and I spend literally days in this program when I'm sorting new Events, so if these issues could be addressed either by an update or if I just need to know some little trick, I would be a much happier customer.
    Thanks in advance.

    Welcome to the Apple Discussions.
    when I apple+backspc. to delete an image, it jumps to the start of the Event
    Yes, that's a bug that's been reported before. Report it at http://www.apple.com/feedback/iphoto.html as the more reports the more likely it will come to the attention of the developers.
    As far as renaming or titling in the thumbnail mode, you have to first click on the title so the title field is activated. Then you can enter any title you'd like.
    You can also batch title files by using the Photos->Batch Change->Title menu option. This will rename them all the same or add a sequential number to the end of the title.
    TIP: For insurance against the iPhoto database corruption that many users have experienced I recommend making a backup copy of the Library6.iPhoto database file and keep it current. If problems crop up where iPhoto suddenly can't see any photos or thinks there are no photos in the library, replacing the working Library6.iPhoto file with the backup will often get the library back. By keeping it current I mean backup after each import and/or any serious editing or work on books, slideshows, calendars, cards, etc. That insures that if a problem pops up and you do need to replace the database file, you'll retain all those efforts. It doesn't take long to make the backup and it's good insurance.
    I've created an Automator workflow application (requires Tiger), iPhoto dB File Backup, that will copy the selected Library6.iPhoto file from your iPhoto Library folder to the Pictures folder, replacing any previous version of it. It's compatible with iPhoto 08 libraries and Leopard. iPhoto does not have to be closed to run the application, just idle. You can download it at Toad's Cellar. Be sure to read the Read Me pdf file.

  • 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 );

  • Script to make landscape and portrait images square

    I am new to scripting and could use a little help.
    We are currently rebuilding our enitre website from the ground up. New look, new products, new images (about 2,800 of them). Here is where it gets tricky.
    Some of the photos are landscape and others are portrait. I have resized the images to the required 200 pixels wide, but we are now running into the issue where they also need to be 200 pixels high. I could just separate them into two folders, landscape and portrait, and run two different actions, but I would prefer to run an if/than script if possible. Can someone tell me if this is possible in Photoshop? These are images of products, so there is no background.
    If the image is larger than 200 pixels high, reduce the image to 200 pixels high. Then, enlarge the canvas to 200 pixels.
    If the image is smaller than 200 pixels high, Then enlarge the canvas to 200 pixels high.
    These are all 72 dpi, RGB images. Any help would be greatly appreciated.

    I have found this JaveScript that does what I need on the PC side, but keep getting an error when it tries to save the image. Is anyone able to recreate this into AppleScript with a correct save function... I am running a MAC, so I need an AppleScript. My coworker has Photoshop on the PC and is trying to use this JavaScript below.
    //  resize canvas  & export JPG
    #target photoshop
    app.bringToFront();
    // Save current dialog preferences
    var startDisplayDialogs = app.displayDialogs;    
    // Save current unit preferences
    app.displayDialogs = DialogModes.NO
    // Source and Destination Folders
    var inputFolder = Folder.selectDialog("Select the Source folder");
    var outputFolder = Folder.selectDialog("Select the Destination folder");
    ProcessImages();
    function ProcessImages() {
      var filesOpened = 0;
       if ( inputFolder == null || outputFolder == null) {
       if ( inputFolder == null) {
                alert("No Source folder selected");
        if ( outputFolder == null) {
           alert("No Destination folder selected");
       }else{
    var fileList = inputFolder.getFiles();
      for ( var i = 0; i < fileList.length; i++ ) {
           if ( fileList[i] instanceof File && ! fileList[i].hidden) {
                     open( fileList[i] );
                     ResizeCanvas();
                     filesOpened++; 
      return filesOpened;
    function ExportJpeg(filePrefix, fileSuffix){
    try
    var docRef = app.activeDocument;
    var docName = app.activeDocument.name.slice(0,-4);
    var jpegOptions = new JPEGSaveOptions();
    jpegOptions.quality = 8
    docRef.flatten()
    docRef.bitsPerChannel = BitsPerChannelType.EIGHT
    jpegFile = new File( outputFolder + "//"  + filePrefix + docName + fileSuffix );
    //Save Document As
    docRef.saveAs(jpegFile, JPEGSaveOptions, true, Extension.LOWERCASE);
    catch (e)
    alert("Error when attempting to save the image. \r\r" + e);
    return;
    function ResizeCanvas()
       function CanvasSize() {
          var docRef = app.activeDocument;
          var docWidth = docRef.width.as("px");
          var docHeight = docRef.height.as("px");  
          if (docWidth < docHeight)
                docRef.resizeCanvas(docWidth = docHeight, docWidth, AnchorPosition.MIDDLECENTER);
          else if (docWidth > docHeight)
                docRef.resizeCanvas(docHeight = docWidth, docHeight, AnchorPosition.MIDDLECENTER);
          else if (docWidth == docHeight)
    var docRef = app.activeDocument;
    var savedState = docRef.activeHistoryState;
    CanvasSize();
    app.displayDialogs = DialogModes.NO;
    ExportJpeg("", ".jpg");
    docRef.activeHistoryState = savedState;
    docRef.close(SaveOptions.DONOTSAVECHANGES);
    docRef = null;
    // Reset preferences
    app.displayDialogs = startDisplayDialogs;
    alert("Operation Complete!" + "\n" + "Images were successfully exported to:" + "\n" + "\n" + outputFolder.toString().match(/([^\.]+)/)[1] + "/");

  • Batch renaming suffix and relinking in InDesign

    Hi,
    It is possible to documents links can be renamed with updated link as suffix "_1 or _2 or _3..........: only do with the new simple script.
    There are many scripts I have found that rename and relink with prefix. I do not find any script that renames and relink with suffix.
    Suppose a file name is "art.ai" if we use prefix scripts it changes like "1_art.ai" in this case both are not in sequence in list preview of 100 links.
    I desperately needed something automatic.
    Thanks,
    Sachin

    Thanks, Rob Day.
    There are many scripts available for prefix.
    I need to add suffix
    Example There are 2 or 3 folders with link.
    When package using book or manually second folders all the link moving in first folder message coming for replace,
    I skip those file, it may be 1, 30, 40 images.
    Again open 2nd document indd and want to rename the linked images with base name + suffix (_1) and relinked,
    Than move all these renamed files in the first folder and repeat in third folder with base name + suffix (_2) and relinked.
    When all the links are in the same folder first repeating images are looking together with there basename + suffix.
    As shown in the screen grab in the post.

  • Batch Renaming in Bridge CS6

    I take pictures of a swim team and I keyword tag each image with the swimmers name.  I would like to batch rename and save in a new folder the files so they have the original filename and then the keyword name.  I don't see that as an option in the metadata drop down or any of the other drop downs.  Is there a way to do it?  I have exported it and included the metadata information and from my PC I can see it in the lower picture data, but I am sharing with a Mac user and it is easiest if the name of the swimmer is in the filename.  I have over 1100 pictures and renaming them manually would be too time consuming.  Thank you for your input.  MB

    I have over 1100 pictures and renaming them manually would be too time consuming.
    Try the Bridge Scripting Forum, if there is a solution possible they can provide you one:
    http://forums.adobe.com/community/bridge/bridge_scripting?view=discussions

Maybe you are looking for