17 Replies Latest reply on Jun 21, 2017 8:58 AM by Jump_Over

    relink images with different names

    ascotto Level 1

      Hi all, I need to relink lots of -missing- images (i.e. "my_favourite_pic_001_LR.jpg") to their high resolution versions (i.e. "my_favourite_pic_001_HR.jpg"). So, is there a way to tell InDesign to 'read' all the characters but the last two before the dot, while searching for links? HR images are all in one folder, so there's no danger to relink wrong ones. I'm pretty a noob with js or applescript, but I'll be glad if someone of you could help me

        • 1. Re: relink images with different names
          Jump_Over Level 5

          Hi,

           

          Here is javascript (place and run from InDesign Script Panel):

          var
            sourceFolder = Folder.selectDialog("Show me a source folder"),
            mLinks = app.activeDocument.links.everyItem().getElements(),
            cLink, cFile;
          
          while ( cLink = mLinks.pop() ) {
            if (cLink.status == LinkStatus.NORMAL) continue;
            cFile = File(sourceFolder + "/" + cLink.name.replace("LR.","HR.") );
            if ( !cFile.exists ) continue;
            cLink.relink(cFile);
            }
          

           

          Jarek

          2 people found this helpful
          • 2. Re: relink images with different names
            ascotto Level 1

            It's amazing, thanks a lot! However, is there a way to add "MR" images or whatever two letters before the dot, to be all relinked to HR ones?

            • 3. Re: Re: relink images with different names
              Jump_Over Level 5

              Hi,

               

              One can use regex in place on 1st parameter of replace method.

              Line 08:

              cFile = File(sourceFolder + "/" + cLink.name.replace(/.{2}\./,"HR.")
              

               

              which means match "any two characters and period"

              Jarek

              • 4. Re: relink images with different names
                ascotto Level 1

                That's exactly what I was looking for. Thanks a lot Jarek!

                • 5. Re: relink images with different names
                  AndreasNRW

                  Hey @Jump_Over!

                   

                  I think this Script might help me! But i need something little different here, is it possible to change the Script in the way i need it? I will try to explain:

                   

                  I've got a lot of missing images in my indesign file too (linked pdf files), and i want to relink them with new pdf files all with COMPLETE different names. So i would like that the Script automatically relink all missing pdf files with all the new ones with the different names.

                   

                  It is not necessary in which sequence the pdf files will be replaced, it is only important that all missing files will be replaced with all the new ones. And one last note: The number of old missing files and the new files for relink will be always the same, so for example if i got 30 missing files i want to relink them with 30 new ones.

                   

                  Thx for any help !

                  • 6. Re: relink images with different names
                    Jump_Over Level 5

                    AndreasNRW  napisał(-a)

                     

                    ...So i would like that the Script automatically relink all missing pdf files with all the new ones with the different names...

                    What about the way by which a proper name for relinking is chosen?

                    Are you going, for example, to create a TXT list with 'old name - new name' lines?

                    How would you did it manually?

                     

                    Jarek

                    • 7. Re: relink images with different names
                      AndreasNRW Level 1

                      Ok i try to explain it in more detail:

                       

                      1.) One InDesign Document with 30 pages, on each page i placed only 1 linked pdf file. So i have a Folder with 30 single pdf files, each file only placed once on each of the 30 indesign pages. Each pdf file has a different name.

                       

                      2.) Now, i got 30 new single pdf files, all new 30 files got new names, all different than the old 30 files which were linked in the indesign document. I only want indesign to automatically re-link/replace all the new 30 pdf files with the old ones, no matter that the new ones got different names. Because they got different names than the old ones, i have to manually re-link every single pdf on every single side at the indesign document and tell indesign which old file to replace with which new file.

                       

                      EXAMPLE: InDesign PAGE 1 -> PDF-File linked (Name: "Job_A 1467.pdf") – re-link manually with new file (Name: "Job_B 1579.pdf"). If you do this again and again for about 300, 400, 500 pages (sometimes my documents are that big) that is a big effort and takes much time.

                       

                      The size and file format of the new files will be every time still identical, only the file names are changing. The important one would be that the script automatically replaces all 30 old files with the new 30 files, in which order the new files are replaced doesn’t matter. (sure the most logical order would be to do it like (1,2,3,4 ...) or (A, B, C, D ...)

                       

                      In other much shorter words: I only want to tell InDesign “you had linked these 300 files”, i delete them or move them, now you are missing them -> NOW please relink it with this new folder also with 300 files, but they got different names, but please DONT care about the different names or in which order they got placed in the indesign document, just relink all 300 old files with the 300 new files from the new folder automatically without asking me for every single page again which file you should take for replacing”.

                       

                      I hope i managed it to explain my problem so everyone can understand it!

                      • 8. Re: relink images with different names
                        Jump_Over Level 5

                        Hi,

                         

                        Try this:

                         

                        var 
                          sourceFolder = Folder.selectDialog("Show me a source folder"), 
                          mLinks = app.activeDocument.links.everyItem().getElements(), 
                          mFiles = sourceFolder.getFiles(function (cFile) {if (cFile instanceof File) return true; return false}),
                          cLink, cFile; 
                        
                        while ( cLink = mLinks.pop() ) { 
                          if (cLink.status == LinkStatus.NORMAL) continue; 
                          cFile = mFiles.pop(); 
                          if ( !cFile ) break; 
                          cLink.relink(cFile); 
                          }
                        

                         

                        Jarek

                        • 9. Re: relink images with different names
                          AndreasNRW Level 1

                          Hey Jump_Over,

                           

                          wow really big thx for your fast help!! I tried it right now and it worked fine!

                           

                          But i forgot to mention something....sorry! (i thought it would work that way too but it seems there is a modification needed in the script).

                           

                          If i got an indesign file with for example 5 pages and on each page only 1 pdf is placed, your script does the job like it should, no problems!

                           

                          But sometimes i have the same pdf file placed over 2 or 3 indesign pages, but on each page with a different image section (different positioning in the indesign frame where it is placed). I tried your Script with a document where my files are placed like this:

                          InDesign -> 10 pages, but i've got only 5 linked pdf files, each file palced twice in the indesign document. Your Script now replaced 5 pdf files on 5 indesign pages, the other 5 pages remained untouched with the old missing pdf files.

                           

                          An example for better understanding how it is build and what i need:

                           

                          Old Files placed like this:

                          InDesign Page 1 -> Placed PDF File "Job_A_3.pdf"

                          InDesign Page 2 -> Placed PDF File "Job_A_3.pdf"

                          InDesign Page 3 -> Placed PDF File "Job_A_4.pdf"

                          InDesign Page 4 -> Placed PDF File "Job_A_4.pdf"

                          (...)

                           

                          If i get the new files, i would like that it replaces them like they was placed before on each side, like this:

                           

                          New Files should placed like this:

                          InDesign Page 1 -> Placed PDF File "Job_B_7.pdf"

                          InDesign Page 2 -> Placed PDF File "Job_B_7.pdf"

                          InDesign Page 3 -> Placed PDF File "Job_B_8.pdf"

                          InDesign Page 4 -> Placed PDF File "Job_B_8.pdf"

                          (...)

                           

                          Sorry that i didn't explained that immediately in my first post... you think it is possible to add this to the script ?

                           

                          Greetings,

                          AndreasNRW

                          • 10. Re: relink images with different names
                            Jump_Over Level 5

                            Hi,

                             

                            Yes, that's possible. You (I?) can use a separate function for relinking and checking next steps.

                            Alike this:

                            var 
                              sourceFolder = Folder.selectDialog("Show me a source folder"), 
                              mLinks = app.activeDocument.links.everyItem().getElements(), 
                              mFiles = sourceFolder.getFiles(function (cFile) {if (cFile instanceof File) return true; return false}),
                              cLink, cFile; 
                            
                            while ( cLink = mLinks.pop() ) { 
                              if (cLink.status == LinkStatus.NORMAL) continue; 
                              cFile = mFiles.pop(); 
                              if ( !cFile ) break; 
                              mRelink(cLink, cFile);
                              }
                            function mRelink(oldLink, newFile) {
                                var oldName = oldLink.name;
                                do {
                                    oldLink.relink(newFile);
                                    oldLink = app.activeDocument.links.item(oldName);
                                    } while (oldLink.isValid)
                                }
                            

                             

                            Jarek

                            1 person found this helpful
                            • 11. Re: relink images with different names
                              AndreasNRW Level 1

                              Hey, i had the time and tested it with a big indesign file with many pages. That was exactly what I was looking for, it worked perfect! Thank you very much Jarek for your help!!

                              • 12. Re: relink images with different names
                                antoine_c

                                Hey Jarek,

                                I've used your first script (the one for the original query) but after selecting a folder nothing seems to happen. From the original script all I've done is replaced this:

                                 

                                  cFile = File(sourceFolder + "/" + cLink.name.replace("LR.","HR.") );

                                by that:

                                 

                                  cFile = File(sourceFolder + "/" + cLink.name.replace("low_res","high_res") );

                                 

                                my filename structure is slightly different: low_res_image_1.jpg and high_res_image_1.jpg. Should the above change search for links with the term 'low_res' and replace with the ones that have 'high_res'.

                                 

                                I've tried to places low and high res in the same folder then different folders, no luck! Perhaps you could point me to where I seem to go wrong?

                                 

                                Thanks in advance!

                                • 13. Re: relink images with different names
                                  Jump_Over Level 5

                                  Hi,

                                   

                                  Basically - it should work.

                                   

                                  Old files should be missed (hide them to switch link status).

                                  New files should be located in a chosen folder (1 level).

                                   

                                  Jarek

                                  • 14. Re: relink images with different names
                                    antoine_c Level 1

                                    What do you mean by 'hide them to switch link status'? I'm not sure I fully understand what I should do there?

                                    Thanks again!

                                    • 15. Re: relink images with different names
                                      Jump_Over Level 5

                                      I ment to move old files from original folder or to delete them --> in a doc link status will turn to "MISSED" (red circle)

                                       

                                      Jarek

                                      1 person found this helpful
                                      • 16. Re: relink images with different names
                                        antoine_c Level 1

                                        PERFECT! Thanks very much, it works brilliantly, the only thing is that I have to do it individually for each Indd files. Is there a way to apply this script to all open windows for example? That's very minor now... Regardless many thanks for your help Jarek!

                                         

                                        antoine.

                                        1 person found this helpful
                                        • 17. Re: relink images with different names
                                          Jump_Over Level 5

                                          antoine_c  napisał(-a)

                                           

                                          ...Is there a way to apply this script to all open windows for example?...

                                          redefine a source variable:

                                           

                                          mLinks = app.documents.everyItem().links.everyItem().getElements()

                                           

                                          Jarek