3 Replies Latest reply on Aug 14, 2015 11:12 AM by Peter Spier

    Update all instances of a word to be a hyperlink

    martinpublishingservices

      I found a thread from 2010 that seems to have answered my question BUT the script did not work for me.  I am running CC 2014.

       

      I want to find all instances of "coconut" and turn it into a hyperlink that goes to "http://mylink.com" when you click on the word "coconut".

       

      Here is the thread that I found:  Replacing occurrences of a word by links

       

      And here is the script from that thread (it's the first script referenced and is marked "correct answer").

       

      1. app.changeGrepPreferences = NothingEnum.nothing; 
      2. app.findGrepPreferences = NothingEnum.nothing; 
      3. app.findGrepPreferences.findWhat = "SEARCH"
      4. var erg = app.activeDocument.findGrep ();      
      5.  
      6. for (var i = erg.length - 1; i >= 0; i--) { 
      7.     var _hlinkSource = app.activeDocument.hyperlinkTextSources.add(erg[i]); 
      8.     var _destination = app.activeDocument.hyperlinkURLDestinations.add("http://www.google.de"); 
      9.     app.activeDocument.hyperlinks.add(_hlinkSource, _destination); 

       

      TIA