2 Replies Latest reply on Feb 14, 2017 7:57 AM by roba75280674

    Use script and Grep to creat unique hyperlinks

    roba75280674 Level 1

      I'm new to scripting and was wondering if it would be possible to creat unique hyperlinks based on a grep?

       

      I have an indesign file with lots of six digit item numbers. Can I grep for \d{6} and create a hyperlink like google.com/123456 with that number as the anchor text? The digits are unique but the base URL is the same throughout (In this example google.com/).

       

      I was trying with AppleScript but if the number repeated then the script failed.

       

      Any help is is much appreciated.

       

      Thank you

        • 1. Re: Use script and Greg to creat unique hyperlinks
          Liphou Level 1

          Bonjour roba,

           

          Regarde -> Create hyperlinks with script, without big increases to size and processing reqs of resulting PDFs?

           

          voici :

           

          #target "indesign-12.064"  // CC2017
          
          app.findGrepPreferences = app.changeGrepPreferences = null;
          
          var doc = app.activeDocument;
          
          app.findGrepPreferences.findWhat = '\\d{6}';
          
          var objs = doc.findGrep();
          
          for (var i = 0; i < objs.length; i++) {
          //
          
             
              var currTarget  = objs[i];
          
              var lnkDest = doc.hyperlinkURLDestinations.add("http://www.indesignjs.de/extendscriptAPI/indesign-latest/#Application.html");
          
              var lnkSrc = doc.hyperlinkTextSources.add(currTarget);
          
              var lnk = doc.hyperlinks.add(lnkSrc, lnkDest);
          
          }
          
          alert('Processed '+objs.length+' hyperlinks');
          

           

          cet exemple est tiré du lien cité plus au il fonction.

          • 2. Re: Use script and Grep to creat unique hyperlinks
            roba75280674 Level 1

            I think I solved it with this:

             

             

            var myDoc = app.activeDocument; 
            
            app.findGrepPreferences = app.changeGrepPreferences = null; 
            
            
            
            app.findGrepPreferences.findWhat = "\\d{6}-.{2}"; 
            
            var myFound1 = myDoc.findGrep(); 
            
               
            
            count = 0 
            
            for(k=0; k<myFound1.length; k++) 
            
            { 
            
            try{ 
            
            var myFind = myFound1[k];
            
            var myFound = (myFound1[k].contents);
            
            var classNo = myFound.split("-");
            
            var myHyperlinkSource = app.activeDocument.hyperlinkTextSources.add(myFound1[k]) 
            
            var myHyperlinkURLDestination = app.activeDocument.hyperlinkURLDestinations.add("https://www.apexprd.org/scripts/webtrac.wsc/Wbsearch.html?xxmod=AR&xxactivitynumber="+classNo[0])  
            
            var myHyperlink = app.activeDocument.hyperlinks.add(myHyperlinkSource, myHyperlinkURLDestination, {name: myFound1[k].contents+count++}) 
            
            count++ 
            
            }catch(e){} 
            
            } 
            
            
            
            alert(count/2 + " occurencces is changed") 
            
            
            1 person found this helpful