5 Replies Latest reply on Apr 3, 2014 9:55 PM by Jump_Over

    Script works fine in CC but not CS5… Any tips?

    josh009

      So i have this script that detects instances of XXXXXXXX and turns them into hyperlinks. It works fine in InDesign CC however won't play nice in CS5.

       

      Anyone have any tips as to how I can go about making it work?

       

      var myDoc = app.activeDocument;

      var myLinkStyle = myDoc.characterStyles.itemByName("link"); // the Character style of the links

      var myURL = "http://www.abc.com.au/part/{part_id}?utm_source=ABC%PublicationName&utm_medium=Catalogue&utm_term={part_id}&utm_campa ign=Catalogue"; // url of your company

      var myUrlPartReplace = new RegExp("{part_id}", 'g');

      var i, myLinks, myLink, mySource, myDestination;

      for (i = myDoc.hyperlinkTextSources.length-1; i >= 0; i--){

          mySource =  myDoc.hyperlinkTextSources[i];

          if (mySource.sourceText.appliedCharacterStyle == myLinkStyle){

              mySource.remove(); // removes existing hyperlinks to avoid "double bookings"

          }

      }

      app.findGrepPreferences = null;

      app.findGrepPreferences.findWhat = "\\<(\\d\\d\\d\\d\\d\\d\\d\\d)\\>";

      myLinks = myDoc.findGrep();

      app.findGrepPreferences = null;

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

         myLink = myLinks[i];

         mySource = myDoc.hyperlinkTextSources.add(myLink);

         myDestination = myDoc.hyperlinkURLDestinations.add(myURL.replace(myUrlPartReplace, myLink.contents.replace(" ", "")));

         myDoc.hyperlinks.add(mySource, myDestination);

      }

       

      Thanks in advance!