2 Replies Latest reply on Sep 23, 2009 8:41 AM by Ken Hutchinson

    Running a CS3 Script in CS4 (JSX)

    Ken Hutchinson

      I have a javascript for InDesign CS3 written by Olav, and I'm trying to use it now in CS4 since I've upgraded.

       

      Can someone help me to get this running in CS4?

      I'm not sure what changes, if any, are needed.


      The file currently resides in the following folder:

      C:\Program Files\Adobe\Adobe InDesign CS4\Scripts\Scripts Panel

       

      I tried uploading the .jsx file as an attchment, but the forum said that files of that were not allowed. I copied and pasted the text below:

       

       

      //UpdatePrices.jsx 
      //An InDesign CS3 JavaScript 
      // 
      //Updates values of all text formatted using a specified paragraph style. 
      //
      main();
      function main(){
          //If no documents are open, then do nothing. 
          if(app.documents.length !=0){ 
              //If the document does not contain any text, or if the document does not contain any paragraph styles, then do nothing. 
              if((app.activeDocument.stories.length != 0)&&(app.activeDocument.paragraphStyles.length > 1)){
                  myDisplayDialog(); 
              } 
          }
      }
      function myDisplayDialog(){ 
          //Get a list of the paragraph style names from the active document (for use in the dialog box). 
          var myStyleNameList = new Array; 
          for(myStyleCounter = 0; myStyleCounter < app.activeDocument.paragraphStyles.length; myStyleCounter ++){
              if(app.activeDocument.paragraphStyles.item(myStyleCounter).name != "[No paragraph style]"){
                  myStyleNameList.push(app.activeDocument.paragraphStyles.item(myStyleCounter).name);
              } 
          } 
          var myDialog = app.dialogs.add({name:"UpdatePrices"});
          with(myDialog.dialogColumns.add()){ 
              with(dialogRows.add()){ 
                  staticTexts.add({staticLabel:"Percentage Change:"}); 
                  var myPercentageField = percentEditboxes.add({editValue:5}); 
              } 
              with(dialogRows.add()){ 
                  staticTexts.add({staticLabel:"Paragraph Style:"}); 
                  var myParagraphStyleDropdown = dropdowns.add({stringList:myStyleNameList, selectedIndex:0});
              } 
          } 
          var myResult = myDialog.show(); 
          if(myResult == true){ 
              //Get the control settings from the dialog box. 
              var myPercentage = myPercentageField.editValue; 
              var myParagraphStyleName = myStyleNameList[myParagraphStyleDropdown.selectedIndex]; 
              myDialog.destroy(); 
              myUpdatePrices(myPercentage, myParagraphStyleName); 
          } 
          else{ 
              myDialog.destroy(); 
          } 

      function myUpdatePrices(myPercentage, myParagraphStyleName){ 
          var myFoundItem, myPrice; 
          app.findGrepPreferences = NothingEnum.nothing;
          app.findGrepPreferences.findWhat = "\\$\\d*.\\d*";
          app.findGrepPreferences.appliedParagraphStyle = app.activeDocument.paragraphStyles.item(myParagraphStyleName);
          myPercentage = (myPercentage + 100)*.01;
          var myFoundItems = app.activeDocument.findGrep(true); 
          if(myFoundItems.length != 0){
              for(myCounter = 0; myCounter < myFoundItems.length; myCounter ++){
                  myFoundItem = myFoundItems[myCounter];
                  myStartCharacter = myFoundItem.characters.item(1);
                  myEndCharacter = myFoundItem.characters.item(-1);
                  myFoundItem = myFoundItems[myCounter].texts.itemByRange(myStartCharacter, myEndCharacter);
                  myFoundItem.contents = myMakePrice(myFoundItem.contents*myPercentage); 
              } 
          } 
          app.findGrepPreferences = NothingEnum.nothing;
      }
      function myMakePrice(myValue){ 
          var myString = "" + Math.round(myValue * 100) / 100;
          var myIndex = myString.indexOf('.');
          if (myIndex < 0){ 
              return myString + ".00"; 
          } 
          var myPrice = myString.substring(0, myIndex + 1) + myString.substring(myIndex + 1, myIndex + 3);
          if (myIndex + 2 == myString.length){ 
              myPrice += "0"; 
          } 
          return myPrice;
      }