6 Replies Latest reply on Aug 3, 2016 2:17 AM by Dinafanoe

    Girls need help with a script to relink to a different folder in indesign

    Dinafanoe

      I REALLY hope you clever people can help me.

       

      We have switched servers meaning all of our Indesign docs now have broken links. To manually "relink to folder" causes Indesign to crash :-(. And it takes forever so I am hoping to find a script that can relink all links in  the doc to a new file structure.

      The name of the link (file name) and the file structure remains the same; it just point to another server. The structure contains subfolders so the best way would be if the script can see in subfolders as well but otherwise I would gladly use a script that points the one of the 6 subfolders at a time.

       

      Problem - I DONT KNOW ANY SCRIPTS and I am a graphic designer so I cant create scripts :-(. I have previously had success googling a script for i.e. ungrouping everything in the document but I only know how to run the script; NOT to create them.

       

      ANY help in this forum? I have 6 designers waiting for me to solve this.

       

      Is there a script where I could just change the path and then it would relink??

       

      We have iMacs OSX Yosemite 10.10.4

       

      PLEASE HELP.... :-)

       

      /Dina

        • 1. Re: Girls need help with a script to relink to a different folder in indesign
          tpk1982 Level 4

          try this.. this is created by Vamitul

           

          function main() { 

              var doc = app.activeDocument; 

              var myLinks = doc.links.everyItem().getElements(); 

              var linkObj = {}; 

              // create inital object 

              /* linkObject {

                              [path]{missingNr,

                                     arrayOfMissingLinks}

                                     } */ 

           

           

              for (var i = 0; i < myLinks.length; i++) { 

                  if (myLinks[i].status == LinkStatus.LINK_MISSING) { 

                      var myPath = File(myLinks[i].filePath).path.toString(); 

                      if (linkObj[myPath] == undefined) { 

                          linkObj[myPath] = { 

                              missingNr: 1, 

                              missingLinks: [myLinks[i]], 

                              newPath: '' 

                          } 

           

           

                      } else { 

                          linkObj[myPath].missingNr++; 

                          linkObj[myPath].missingLinks.push(myLinks[i].getElements()[0]); 

                      } 

                  } 

              } 

              //$.writeln(linkObj.toSource()); 

              var myDialog = new Window('dialog', 'Link Chaser:', undefined); 

              var panel1 = myDialog.add('panel', undefined, 'Double click to select new path'); 

              panel1.align = ['fill', 'fill']; 

              var myList = panel1.add('listBox', undefined, "", { 

                  columnWidths: [160, 160, 130], 

                  numberOfColumns: 3, 

                  showHeaders: true, 

                  columnTitles: ['Old Path', 'New Path', 'Nr. of missing links'] 

              }); 

              myList.size = [450, 200]; 

              myList.align = ['fill', 'fill']; 

           

           

              for (var missingPath in linkObj) { 

                  with(myList.add('item', missingPath)) { 

                      subItems[0].text = linkObj[missingPath].newPath; 

                      subItems[1].text = linkObj[missingPath].missingNr; 

                  } 

              } 

              myList.onDoubleClick = function() { 

                  var myNewPath = (new Folder(app.activeDocument.filePath).selectDlg("Select New Folder") || '').toString(); 

                  myList.selection.subItems[0].text = myNewPath; 

                  linkObj[myList.selection.text].newPath = myNewPath; 

              } 

              myDialog.add('button', undefined, "Ok", { 

                  name: "ok" 

              }); 

              myDialog.add('button', undefined, "Cancel", { 

                  name: "cancel" 

              }); 

              if (myDialog.show() == 1) { 

                  for (var i in linkObj) { 

                      if (linkObj[i].newPath != '') { 

                          var fixedNr = 0; 

                          var links = linkObj[i].missingLinks 

                          for (var j = 0; j < links.length; j++) { 

                              var newFile = File(linkObj[i].newPath + "/" + links[j].name); 

                              if (newFile.exists) { 

                                  fixedNr++; 

                                  links[j].relink(newFile); 

                              } 

           

           

                          } 

                          alert('In folder:\n' + linkObj[i].newPath + '\n' + 

                              'Fixed ' + fixedNr + ' links out of ' + linkObj[i].missingNr + '\n' + 

                              'Please check'); 

                      } 

                  } 

              }; 

          app.doScript('main()', undefined, undefined, UndoModes.entireScript, "Link Chaser"); 

          • 2. Re: Girls need help with a script to relink to a different folder in indesign
            Dinafanoe Level 1

            I am sorry – I couldn’t replay on the forum??

             

            the only thing I knew was to copy the script into Script editor on mac but it wouldn’t save it (something with the "function main”???)

             

            And I assume that I should enter the path somewhere? I really need specifics …. :-).

             

            THANK you

            • 4. Re: Girls need help with a script to relink to a different folder in indesign
              Peter Kahrel Adobe Community Professional & MVP

              > I am a graphic designer so I cant create script

               

              What strange logic. Some of the best script writers are graphic designers!

               

              Peter

              • 5. Re: Girls need help with a script to relink to a different folder in indesign
                Dinafanoe Level 1

                Haha Peter ... yes indeed. Meaning that my skills are more in the creative department; not the technical.

                 

                But the script worked so I AM HAPPY :-D

                • 6. Re: Girls need help with a script to relink to a different folder in indesign
                  Dinafanoe Level 1

                  You are my saviour – I figured it our and it worked - THANKS

                   

                   

                  Dina Fanoe

                   

                   

                  Moderator: I took out your personal credentials, not safe on a public forum