8 Replies Latest reply on May 20, 2009 6:11 AM by கற்பனை (Imagine)

    Change Hyperlinks

    johnBking78 Level 1

      I have a indesign cs3 file with loads of Hyperlinks and want to replace the first part of that link with another:

       

      Example:

      Find this:

      http://forums.adobe.com/

      Change to this:

      http://forums.com/

       

       

      is there a way to find and change Hyperlinks?

       

       

      Thank you

        • 1. Re: Change Hyperlinks
          Olav Martin Kvern Level 3

          Hi jamb71,

           

          Try something like this:

           

          var myDestinationURL;

          var myDocument = app.documents.item(0);
          var findWhat = "http//forums.adobe.com";
          var changeTo = http://forums.com";
          if(myDocument.hyperlinkURLDestinations.length > 0){
          for(var myCounter = myDocument.hyperlinkURLDestinations.length -1; myCounter >=0; myCounter--){
            myDestinationURL = myDocument.hyperlinkURLDestinations.item(myCounter).destinationURL;
            if(myDestinationURL.search(findWhat) != -1){
             myDocument.hyperlinkURLDestinations.item(myCounter).destinationURL = myDestinationURL.replace(findWhat, changeTo);
            }
          }
          }

           

          Thanks,

           

          Ole

          • 2. Re: Change Hyperlinks
            johnBking78 Level 1

            Thanks Ole, that works just fine, it even finds part of an address, which is very handy.

             

             

            Many thanks!

             

             

            PS: is there anyway to style tables with a script, I can't fine any answers, all I'm after is to add a one cell style to the header row, then a different cell style to the rest of the table?

             

            is it even possible?

            • 3. Re: Change Hyperlinks
              johnBking78 Level 1

              Olav Kvern was kind enough to help me with this question, which works on most of my links, but some don't see below:

               

              ..\folder\another\test.pdf

               

              and change it to:

               

              ../folder/another/test.pdf

               

              When I try the script below it will not work? it won't change the backslash for a forward one? can anyone help!

               

              var myDestinationURL;
              var myDocument = app.documents.item(0);
              var findWhat = "..\folder\another\test.pdf";
              var changeTo = "../folder/another/test.pdf";
              if(myDocument.hyperlinkURLDestinations.length > 0){
              for(var myCounter = myDocument.hyperlinkURLDestinations.length -1; myCounter >=0; myCounter--){
                myDestinationURL = myDocument.hyperlinkURLDestinations.item(myCounter).destinationURL;
                if(myDestinationURL.search(findWhat) != -1){
                 myDocument.hyperlinkURLDestinations.item(myCounter).destinationURL = myDestinationURL.replace(findWhat, changeTo);
                }
              }
              }
              

              Thank you.

              • 4. Re: Change Hyperlinks
                Olav Martin Kvern Level 3

                Hi jamb71,

                 

                It's probably because the backslash is a special character in JavaScript strings. To make it appear, you have to "escape" it--which involves (you guessed it) another backslash. Try:

                 

                var findWhat = "..\\folder\\another\\test.pdf";

                Thanks,

                 

                Ole

                • 5. Re: Change Hyperlinks
                  johnBking78 Level 1

                  Fantastic that works really well, I do have a lot of different links, is there any way just to find \\ and change to /

                   

                  Although this does not work, but something like this:

                  var findWhat = "\\";
                  var changeTo = "/";
                  

                   

                   

                  if not I could just look for all characters in the alphabet, but this could be the wrong:

                  var findWhat = "\\a";
                  var changeTo = "/a";
                  

                  var findWhat = "\\b";
                  var changeTo = "/b";
                  

                   

                   

                  Thanks again Olav!

                  • 6. Re: Change Hyperlinks
                    கற்பனை (Imagine) Level 3

                    Hi jamb,

                     

                    Use the below replace function...

                     

                    myNewLink = myLinkString.replace ("\\", "/");

                     

                    Thanks,

                    Nagaraj

                    • 7. Re: Change Hyperlinks
                      johnBking78 Level 1

                      Thank you Nagaraj1983

                       

                      Only thing is I am so new to this, I am unsure how to implement this in a running script?

                       

                      any pointers would be great.

                       

                       

                      Many thanks

                      • 8. Re: Change Hyperlinks
                        கற்பனை (Imagine) Level 3

                        Hi jamb,

                         

                        Check the below script .......  In my guess working the script...

                         

                        var myDestinationURL;
                        var myDocument = app.documents.item(0);
                        var findWhat = "..\\folder\\another\\test.pdf";
                        var changeTo = findWhat.replace (/\\/g,"/");
                        //var changeTo = "../folder/another/test.pdf";
                        if(myDocument.hyperlinkURLDestinations.length > 0){
                        for(var myCounter = myDocument.hyperlinkURLDestinations.length -1; myCounter >=0; myCounter--){
                          myDestinationURL = myDocument.hyperlinkURLDestinations.item(myCounter).destinationURL;
                          if(myDestinationURL.search(findWhat) != -1){
                           myDocument.hyperlinkURLDestinations.item(myCounter).destinationURL = myDestinationURL.replace(findWhat, changeTo);
                          }
                        }
                        }