9 Replies Latest reply on Oct 18, 2016 6:55 AM by Loic.Aigon

    Alerts for multiple Documents

    cbishop01 Level 2

      Hi what i'm trying to do is Display the amount of corrections that were made in an alert.  i have it set and working for one document.  but when i change text on multiple documents it will not display the Amount Corrected.  It will correct them but just not display a number. The part i'm having trouble with is Line 9.  As indicated.  If its off The Amount Of corrections in my alert will display correctly(Only for the active Document).  If its On the corrections will Be done to all Documents (If my All Documents Check box is active.) but will not display a total amount of corrections for all documents.  In a nut shell i'm wanting this to perform like the Find/Replace built into indesign.  Display All Corrections made.  If i have 10 documents with 1 correction each.  I want it to display 10 if i only want to check one document i want it to display 1.  Can someone help me with this?


      function DBLS(target, findProps, changeProps){     
       var changes, numCHGS, alerts, alerts1, alert2;
        app.findChangeTextOptions.caseSensitive = true;     
        app.findGrepPreferences = app.changeGrepPreferences = null;     
        app.findGrepPreferences.properties = findProps;     
        app.changeGrepPreferences.properties = changeProps;
          //    target.changeGrep(); // This is what makes the correction work on all open Documents. If this is turned on it will not allow me to display the amount of corrections.   It just shows up as 0 If this is off like now it will display The amount of Correction (Only on active Page)
              changes = app.documents[0].changeGrep();
              numCHGS = changes.length;
              alerts = [numCHGS+"   Double Space", SP+"   Space Period", SC+"   Space Colon", DR+"   Double Return"];
              alerts1 = [ENG+"   Important Statement and MSDS"];
              alerts2 = [CCH+"    Pink ? to A Contains", CE+"    Pink ? to E Contains", CK+"    Pink ? to K Contains", spCOM+"    Space Comma"];
       alert("Corrections Made:\r"+alerts.join("\r")+"\r-----------------------------------\rImportant and SDS:\r-----------------------------------\r"+alerts1.join("\r")+"\r-----------------------------------\rCONTAINS:\r-----------------------------------\r"+alerts2.join("\r"));
        • 1. Re: Alerts for multiple Documents
          tpk1982 Level 4

          change line 9 with this..


          changes = app.documents.everyItem().changeGrep(); 


          documents[0] means the active document




          1 person found this helpful
          • 2. Re: Alerts for multiple Documents
            Loic.Aigon Adobe Community Professional



            There is a fundamental difference between activeDocument property and documents[0]. activeDocument does access the item zero of the app's documents collection. So the lack of open documents will throw an error immediately.


            Using documents[0] doesn't necessarly throw error as long as you don't try to reach any property of methods. So you can have a script """"working""""" with documents[0] even if there isn't any document open.


            So in both case, it's worth preventing hiccups by either check:

            app.properties.activeDocument //will return undefined but no error thrown when app.activeDocument can.


            documents[0].isValid as isValid will check the reference status and return either true/false.





            1 person found this helpful
            • 3. Re: Alerts for multiple Documents
              tpk1982 Level 4

              Thanks Loic for your detailed explanation

              • 4. Re: Alerts for multiple Documents
                cbishop01 Level 2

                Great explanation thank you.

                • 5. Re: Alerts for multiple Documents
                  cbishop01 Level 2

                  This worked for all documents thanks.  The changes happen for all documents still not displaying correctly in my count though.  It does show up that there are corrections but it shows the number of documents corrected.  Not the total number of characters Corrected. Examples below:

                  the 4 is the total Corrected Documents.  i Want it to display Total Corrections For all pages.

                  Screen Shot 2016-10-18 at 8.20.05 AM.png

                  This is what i want the above script to display.  The above should say 6040 (Total changes ) not 4 (# Documents). 

                  Screen Shot 2016-10-18 at 8.35.03 AM.png

                  This is how many this should display for this document. This and the one below work Fine for the active document

                  Screen Shot 2016-10-18 at 8.20.57 AM.png

                  This is with the code above for ONLY ACTIVE DOCUMENT.  Which you guys went over already.

                  Screen Shot 2016-10-18 at 8.26.34 AM.png

                  • 6. Re: Alerts for multiple Documents
                    Loic.Aigon Adobe Community Professional

                    Because you got there, you may want to output the result to a log file. Alerts can be a pain with long strings.


                    var result = "Corrections made…";


                    var log = new File(Folder.desktop+"/log.txt");

                    log.encoding = "UTF-8";









                    1 person found this helpful
                    • 7. Re: Alerts for multiple Documents
                      cbishop01 Level 2

                      I have this where it displays the information but it still shows the Number of open Documents (4) as opposed to the Total number of corrections.  I dont mind using a log file it works just as well as the Alert. And i could actually display more information. I'm just still having trouble with displaying the Correct info.

                      • 8. Re: Alerts for multiple Documents
                        cbishop01 Level 2

                        Never mind i got it to display for all documents i changed the


                        changes = app.documents[0].changeGrep();


                        changes = target.changeGrep();

                        Thank you guys so much.  If you see a problem with this let me know. I'm going to like and Mark everything helpful for you guys so you get the points.

                        • 9. Re: Alerts for multiple Documents
                          Loic.Aigon Adobe Community Professional

                          if you call find/change operations on the app object it will process every single open document.