3 Replies Latest reply on May 19, 2016 7:22 PM by Michael Witherell

    Slow down that script

    Michael Witherell Adobe Community Professional

      Hi everyone,


      When you run a script like "FindChangeByList.jsx" included with InDesign, is there a way to edit it and have it show you the next change and wait for you to click on the Change button? How would this be written in javascript?


      Second to that, is there a way to run a script (like FindChangeByList.jsx) and have it inform you how many changes were made (in a dialog box window)?


      Mike Witherell in Maryland

        • 1. Re: Slow down that script
          tpk1982 Level 4



          for the first question you may use Function for every search and call one by one at end of every function..and use confirm to go for the next find and replace

          • 2. Re: Slow down that script
            [Jongware] Most Valuable Participant

            If you look in the code, you can see the functions "myFindText", "myFindGrep" and "myFindGlyph" all store the results of the actual myObject.changeXXX(..) into a variable called myFoundItems. This will thus be an array of the changed text (and it's not used anywhere. Oh well, these are just example scripts.). The number of changes is thus the length of the array: myFoundItems.length.


            You can:

            1. add a global variable at the top, before the line 'main()':


            var NumberOfChanges = 0;


            2. at the end of each of the myFindXXX routines, add a line


            NumberOfChanges += myFoundItems.length;


            3. add an alert at the top, after the line 'main()':


            alert ("Number of changes made: "+NumberOfChanges);


            Not tested but it ought to work.


            Concerning your other point, a manual confirm for each separate find/change: that is way, way more work. You have to remember that InDesign's JavaScript does not 'drive' the interface (like a macro), but rather makes direct calls into the underlying code. So the Find/Change dialog is never "called", and there is no opportunity to somehow 'pause' in the middle of the operation and show the state of that dialog.


            Unfortunately, the Adobe programmers did not add commands for 'find next' and 'change, find next' to its scripting interface. You can Find All or Change All, nothing else. It is possible to use a Find All first, and then loop over its results and manually picking which occurrences to change, but every time you change something, the entire previously found list is invalidated! There is no easy way to 'continue' searching from any random starting point either (and frankly, that seems a recurring problem for Adobe's programmers, because in the interface itself it's also quite erratic at times!).


            Can you tell us more on what the background of your question is?

            • 3. Re: Slow down that script
              Michael Witherell Adobe Community Professional

              Thanks so much, Jongware.

              I guess I would like a bit more reportage and control while I burn through a text cleanup. I would like the ability to look at each potential change, and have the option to skip one sometimes. I would like to be able to say that I saw each and every change the script made, and thus I would know a bit better that I have not inadvertently added unnoticed mistakes into the text cleanup.


              I added your 3 bits of code to my own "FindChangeByListPlus2016.jsx" file. This is an improved version relative to the one that ships pre-installed with InDesign (which has a few shortcomings). In adding your three lines of code, it now finishes with a dialog box message window that informs the total number of changes made.


              That is a step in the right direction! Thanks. I will make it available for download for free from my website.