1 Reply Latest reply on Mar 3, 2014 2:53 AM by Jump_Over

    Script labels and findchangebylist.jsx

    Matthew.Fry

      I am looking for any examples of a script that finds a certain script label on a textframe and then runs findchangebylist.jsx on that textframe.

        • 1. Re: Script labels and findchangebylist.jsx
          Jump_Over Level 5

          Hi,

           

          What you need is

          1. to simplify function

          • main()

          2. and to modify:

          • myFindChangeByList(myObject)
          • myDisplayDialog()

           

          Ad 1.

          function main(){
              var myObject;
              //Make certain that user interaction (display of dialogs, etc.) is turned on.
              app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
              if(app.documents.length > 0) myDisplayDialog();
              else alert("No documents are open. Please open a document and try again.");
          }
          

          Ad 2

          function myFindChangeByList(myObject){
              var myScriptFileName, myFindChangeFile, myFindChangeFileName, myScriptFile, myResult;
              var myFindChangeArray, myFindPreferences, myChangePreferences, myFindLimit, myStory;
              var myStartCharacter, myEndCharacter;
              var myFindChangeFile = myFindFile("/FindChangeSupport/FindChangeList.txt")
              if(myFindChangeFile != null){
                  myFindChangeFile = File(myFindChangeFile);
                  var myResult = myFindChangeFile.open("r", undefined, undefined);
                  if(myResult == true){
                      //Loop through the find/change operations.
                      do{
                          myLine = myFindChangeFile.readln();
                          //Ignore comment lines and blank lines.
                          if((myLine.substring(0,4)=="text")||(myLine.substring(0,4)=="grep")||(myLine.substring(0,5)=="glyph")){
                              myFindChangeArray = myLine.split("\t");
                              //The first field in the line is the findType string.
                              myFindType = myFindChangeArray[0];
                              //The second field in the line is the FindPreferences string.
                              myFindPreferences = myFindChangeArray[1];
                              //The second field in the line is the ChangePreferences string.
                              myChangePreferences = myFindChangeArray[2];
                              //The fourth field is the range--used only by text find/change.
                              myFindChangeOptions = myFindChangeArray[3];
                              switch(myFindType){
                                  case "text":
                                      if (myObject instanceof Array)
                                          for (var k = myObject.length - 1; k >=0; k--)
                                          myFindText(myObject[k], myFindPreferences, myChangePreferences, myFindChangeOptions);
                                      else myFindText(myObject, myFindPreferences, myChangePreferences, myFindChangeOptions);
                                      break;
                                  case "grep":
                                      if (myObject instanceof Array)
                                          for (var k = myObject.length - 1; k >=0; k--)
                                          myFindGrep(myObject[k], myFindPreferences, myChangePreferences, myFindChangeOptions);
                                      else myFindGrep(myObject, myFindPreferences, myChangePreferences, myFindChangeOptions);
                                      break;
                                  case "glyph":
                                      if (myObject instanceof Array)
                                          for (var k = myObject.length - 1; k >=0; k--)
                                          myFindGlyph(myObject[k], myFindPreferences, myChangePreferences, myFindChangeOptions);
                                      else myFindGlyph(myObject, myFindPreferences, myChangePreferences, myFindChangeOptions);
                                      break;
                              }
                          }
                      } while(myFindChangeFile.eof == false);
                      myFindChangeFile.close();
                  }
              }
          }
          function myDisplayDialog(){
              var myObject, mFramesLabels, mFrames = [];
              var myDialog = app.dialogs.add({name:"FindChangeByList"});
              with(myDialog.dialogColumns.add()){
                  with(dialogRows.add()){
                      with(dialogColumns.add()){
                          staticTexts.add({staticLabel:"Search Range:"});
                      }
                      var myRangeButtons = radiobuttonGroups.add();
                      with(myRangeButtons){
                          radiobuttonControls.add({staticLabel:"Document", checkedState:true});
                          radiobuttonControls.add({staticLabel:"Selected Story"});
                          radiobuttonControls.add({staticLabel:"Labeled Frames"});
                          if(app.selection[0] && app.selection[0].hasOwnProperty ("baselineShift") && app.selection[0].contents != ""){
                              radiobuttonControls.add({staticLabel:"Selection", checkedState:true});
                          }
                      }            
                  }
              var myLabel = textEditboxes.add({staticLabel:"Label:", minWidth: 185});
              }
              var myResult = myDialog.show();
              if(myResult == true){
                  switch(myRangeButtons.selectedButton){
                      case 0:
                          myObject = app.documents.item(0);
                          break;
                      case 1:
                          myObject = app.selection[0].parentStory;
                          break;
                      case 2:
                          mFramesLabels = app.documents.item(0).textFrames.everyItem().label;
                          for (var k = 0; k < mFramesLabels.length; k++)
                              if(mFramesLabels[k].length && mFramesLabels[k] == myLabel.editContents)
                              mFrames.push(app.documents.item(0).textFrames[k]);
                          myObject = mFrames;
                          break;
                      case 3:
                          myObject = app.selection[0];
                          break;
                  }
                  myDialog.destroy();
                  myFindChangeByList(myObject);
              }
              else{
                  myDialog.destroy();
              }
          }
          

           

          Make a copy with mentioned function replaced with.

          Enjoy

           

          Jarek