13 Replies Latest reply on Nov 6, 2016 1:04 PM by Kasyan Servetsky

    A script to batch rename and relink images?

    Maira.Damasio

      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!

        • 1. Re: A script to batch rename and relink images?
          Lorenzo_T

          Hi, I don't know a way to rename all the images in InDesign, but if you have a machintosh computer I can easly tell you how to do it

          • 2. Re: A script to batch rename and relink images?
            Maira.Damasio Level 1

            We use Macs in the company, yes. I'd appreciate it. Would that way rename all images AND update the links in InDesign? If it were just renaming it, we could do it in Bridge...

            • 3. Re: A script to batch rename and relink images?
              Adobe-InDesign CS4 Level 1

              Hi Maira

               

              This is Possible in InDesign Windows also.

               

              (1) Collect All images

              (2) Segregate the Extension and Stored one variable

              (3) Store Variable to Add your numbering ....etc...

              (4) now once again add the separated extension value

              (5) Finally rename using Re-Link options.

               

              Thanks & Regards

              T.R.Harihara Sudhan

              • 4. Re: A script to batch rename and relink images?
                Lorenzo_T Level 1

                Well, I had the same problem some days ago. Automator is a default application in machintosh, it allows you to choose a folder and rename al the files in it. You can automate the renaming in sequence (EQ01, EQ02, EQ03). If the link folder of InDesign has different names, all the files will be renamed in sequence.

                 

                Instructions:

                1 - open Automator

                2 - chose workflow

                3 - type "get specified finder items" and double click it to add this action in the workflow

                4 - type "rename finder items" and double click it to add this action in the workflow

                5 - add the folder you have to rename in the first action

                6 - in the second action choose "make sequential"

                7 - set the other name setting in order to get the name you want

                8 - save and choose as "application" in the saving options

                 

                Now you have an action that rename all the files in that folder anytime you click it

                In alternative, you can choose to not save and play the action in automator

                • 5. Re: A script to batch rename and relink images?
                  Maira.Damasio Level 1

                  Harihara: the logic of that makes perfect sense to me, thanks! However, as neither I nor anybody else in the company know how to make scripts, I wouldn't be able to put that to practice.

                   

                  Lorenzo: That would rename all the images, yes... but wouldn't that require us to relink the images one by one in InDesign after the batch renaming?

                  • 6. Re: A script to batch rename and relink images?
                    Lorenzo_T Level 1

                    No, when you rename all the files, InDesign still keep the original links and asks you to update them.

                    Once you renamed all the files, just go on the link panel in InDesign: you will see that all the links have a yellow triangle which means you have to update them

                    > than, you click botton in the top-right corner of the links menu and click "update all links"

                    • 7. Re: A script to batch rename and relink images?
                      Chinnadk Level 4

                      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

                      • 8. Re: A script to batch rename and relink images?
                        Maira.Damasio Level 1

                        Chinnadk:

                        That worked out perfectly! Thank you so much!

                        Any chance you could make it prompt the user for a prefix instead of having it fixed? It was easy enough for us to figure out how to change the script for that specific thing, but we have a big rotation of designers in the company and it could be troublesome to explain to each new one how to change the script.

                        Again, thank you very much

                        • 9. Re: A script to batch rename and relink images?
                          Maira.Damasio Level 1

                          Nevermind, we were able to frankenstein it from other scripts we found in these forums (I hope that's ok!) and it worked beautifully.

                          If anyone else needs it:

                           

                          var myDoc = app.activeDocument; 

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

                           

                           

                          var doc = app.activeDocument, 

                              links = doc.allGraphics, count = 1, eqcount = 1, a = "0000"; 

                          for(var i=links.length-1;i>=0;i--) 

                                          var ext = links[i].itemLink.name.substr(links[i].itemLink.name.lastIndexOf(".")), 

                                              old = File(links[i].itemLink.filePath), 

                                              num = (count++).toString(), 

                                              newname = myPrepend + 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))) 

                              }

                          • 10. Re: A script to batch rename and relink images?
                            photoretouchpro Level 1

                            Can this be modified to apply only to .tif and .psd files? How?

                            Thanks.

                            • 11. Re: A script to batch rename and relink images?
                              Fobioid Level 1

                              Using @Maira.Damasio's script, I found that if a link is used more than once in a document, it will only relink the first occurrence of it, leaving the others as missing links.

                               

                              Is there a fix for this?

                               

                              If nothing else, is there a way to create a .txt log of the old and new file names for reference to manually relink?

                              • 12. Re: A script to batch rename and relink images?
                                Kasyan Servetsky Level 5

                                In this script you can see how to handle multi-placed links -- check out the Relink function.

                                — Kas

                                • 13. Re: A script to batch rename and relink images?
                                  Kasyan Servetsky Level 5

                                  See also this post -- a similar script which handles multi-placed links.