23 Replies Latest reply on Jun 23, 2016 7:13 AM by cbishop01

    How to make this check box Apply to all Documents?

    cbishop01 Level 2

      I'm sure this is probably an easy question.  I've Added another Check BOx (Apply to all Documents) and when its selected i want the changes of the check boxes below it to chage for all open documents.

      var RunCH1, RunCH2, RunCH3, RunCH6, RunCH8;
                  RunCH8= app.documents[0],  
                  allPagesMaPref = RunCH8.pages.everyItem()  ;  
                  RunCH8= w.tabs[1].add ('checkbox {text: "APPLY TO ALL DOCUMENTS"}');
                  RunCH1= w.tabs[1].add ('checkbox {text: "Find and Replace"}');
      

       

       

      Thank you in advance.

        • 1. Re: How to make this check box Apply to all Documents?
          ava74628296 Level 1
          RunCH8.onClick  = function(){
                          if(RunCH8.value == true){ 
                              RunCH1.value = true;
                          }
                          else{
                                  RunCH1.value = false;
                          }
          
          • 2. Re: How to make this check box Apply to all Documents?
            Loic.Aigon Adobe Community Professional

            In this kind of stuff, I would definitively avoid having to tell any of the instances to switch true/false all the time.

             

            Here is a proposal based on a event programming approach:

             

            var main = function() {
              var ev = new EventManager(),
              u;
            
              var cbx = function(p, label, v) {
              var cbx = p.add('checkbox', undefined, label);
              var mainHandler = function(data){
              cbx.value = data.value;
              };
            
              cbx.onClick = function () {
              alert("Hey I am "+cbx.text );
              }
            
            
              //Adding event listeners
              ev.addEventListener ("MAIN_FIRED", mainHandler  );
            
              return cbx;
              };
            
              var w = new Window ('dialog','About CBX & EVENTS');
              var p1 = w.add('panel', u,'MAIN CBX');
              var cbxMain = p1.add('checkbox',u,'MAIN');
            
              cbxMain.onClick = function() {
              ev.dispatchEvent ("MAIN_FIRED", {value:cbxMain.value} );
              };
            
              var i = 0, n=20;
              while ( i<n ) {
              new cbx ( p1, 'Child '+(i+1), false );
              i++;
              }
            
              w.show();
            }
            
            
            main();
            

             

             

            Using a library of mine:

            //Our Pseudo Event Class
            var EventManager = function()
            {
            
              //Our internal key object
              var o  = {
            
              };
            
            
              //return the Event Manager API
              return {
            
              //Add a listener to the class for a specific event
              addEventListener:function(name, handler) {
            
              //Return if the supplied handler already belongs to the listened event
              if ( this.hasEventListener (name, handler) ) return;
            
              //Adding the handler for the event
              o[name] = o[name] || [];
              o[name][o[name].length]=handler;
            
              },
            
              //Executes every handler attached to the event
              //passing data as argument
              dispatchEvent:function(name, data) {
            
              var n, i=0; 
            
              //Return if no handler is set
              if ( !o[name] || !(o[name] instanceof Array) || !o[name].length ) return;
            
              n = o[name].length;
            
              //executes every handler
              for ( i = 0; i<n; i++ ) {
              o[name][i](data);
              }
              },
            
              //Remove a specific handler for the event
              removeEventListener:function(name, handler) {
            
              //We will redefine the internal chain of handlers
              //passing the content of the "new" newArray array
              var newArray = [], n;
            
              //Return if no handler is set
              if ( !this.hasEventListener ( name, handler ) ) return;
            
              n = o[name].length;
            
              //Storing handlers into newArray if different from specific handler
              while ( n-- ) {
              if ( (o[name][n] !== handler) ) {
              newArray [ newArray.length ] = o[name][n];
              }
              }
            
              //Redefining handlers array
              o[name] = newArray ;
            
              },
            
              //Checking if some event host a specific handler
              hasEventListener:function(name, handler) {
              var n;
            
              if ( !o[name] || !(o[name] instanceof Array) || !o[name].length ) return false;
            
              n = o[name].length;
            
              //If handle is found, return true. Otherwise return false
              while ( n-- ) if ( o[name][n] === handler ) return true;
            
              return false;
              },
            
              //Some utility to get access to the handler array for some specific event or all the eventManager class
              expose:function(name){
              if ( name ) {
              if ( !o[name] || !(o[name] instanceof Array) || o[name.length] ) return "no events set";
              else return o[name].toSource();
              }
              else {
              return o.toSource();
              }
              }
              }
            };
            

             

             

            which produces the expected result:

            Capture d’écran 2016-06-20 à 12.35.54.png

             

            And yet allow some differenciation at the child level

             

            Capture d’écran 2016-06-20 à 12.36.16.png

             

            Loic

            Ozalto | Productivity Oriented - Loïc Aigon

            1 person found this helpful
            • 3. Re: How to make this check box Apply to all Documents?
              cbishop01 Level 2

              Thank you. Just for my knowledge. What would the draw back to using the True False statement? 

              • 4. Re: How to make this check box Apply to all Documents?
                Loic.Aigon Adobe Community Professional

                It would basically work the same. But you could then add/withdraw checkboxes without any concerns about previous references.

                It's only a point of view. If you have dozens of boxes, I fond it more manageable.

                 

                FWIW

                 

                Loic

                • 5. Re: How to make this check box Apply to all Documents?
                  cbishop01 Level 2

                  APPLY TO ALL DOCUMETNS = "MAIN"

                  Child 1 = RunCH1, Child 2 = RunCH2 and so on.

                   

                  Also i'm not wanting the top Button in this case "MAIN"  to select every check box under it.  I just want it to apply changes to all the documents when "Main"  and say Child 1 , "MAIN" Child 2 selected. "using your above code as an EX..."

                  I am trying to get Child 1, 2, 3, 4, etc.. to make a change to just a single page.  But when i click on the "MAIN" button I would then want all the already selected *Children* to apply to every document i have opened.

                   

                  If Child 1 Does EX.. *Find and Replace All (T's- A's)* and Child 2 does *Find and replace X's - Y's* and I open 20 Documents And want Child 1 to Change on all documents Only IF the "MAIN" is selected.   WIll this above code do that>

                   

                  I do already have the Find and replace settings

                  Will this above Code accomplish this?  I'm Messing with it now trying to incorporate this with mine to see if i can get it to work.  But you will more than likely Get back to me before / If i accomplish this.  Thanks again for you Help

                  • 6. Re: How to make this check box Apply to all Documents?
                    cbishop01 Level 2

                    RIght now i will have about 5 check boxes.  ON each tab and i have 2 tabs with check boxes. 

                    • 7. Re: How to make this check box Apply to all Documents?
                      cbishop01 Level 2

                      Thank you for your suggestion as well.

                      • 8. Re: How to make this check box Apply to all Documents?
                        Loic.Aigon Adobe Community Professional

                        Oh I can see now what you are trying to achieve.

                         

                        Well, I would probably do something similar. Every time a checkbow would be hit, I would fire an event that would affect a specific variable object. Then when my master routine is run, I would look at this specific object what needs to be done, rather than loop through every single box.

                        Consider it as a """"pseudo"""" mvc implementation.

                         

                        //Our Pseudo Event Class  
                        var EventManager = function()  
                        {  
                          
                          //Our internal key object  
                          var o  = {  
                          
                          };  
                          
                          
                          //return the Event Manager API  
                          return {  
                          
                          //Add a listener to the class for a specific event  
                          addEventListener:function(name, handler) {  
                          
                          //Return if the supplied handler already belongs to the listened event  
                          if ( this.hasEventListener (name, handler) ) return;  
                          
                          //Adding the handler for the event  
                          o[name] = o[name] || [];  
                          o[name][o[name].length]=handler;  
                          
                          },  
                          
                          //Executes every handler attached to the event  
                          //passing data as argument  
                          dispatchEvent:function(name, data) {  
                          
                          var n, i=0;   
                          
                          //Return if no handler is set  
                          if ( !o[name] || !(o[name] instanceof Array) || !o[name].length ) return;  
                          
                          n = o[name].length;  
                          
                          //executes every handler  
                          for ( i = 0; i<n; i++ ) {  
                          o[name][i](data);  
                          }  
                          },  
                          
                          //Remove a specific handler for the event  
                          removeEventListener:function(name, handler) {  
                          
                          //We will redefine the internal chain of handlers  
                          //passing the content of the "new" newArray array  
                          var newArray = [], n;  
                          
                          //Return if no handler is set  
                          if ( !this.hasEventListener ( name, handler ) ) return;  
                          
                          n = o[name].length;  
                          
                          //Storing handlers into newArray if different from specific handler  
                          while ( n-- ) {  
                          if ( (o[name][n] !== handler) ) {  
                          newArray [ newArray.length ] = o[name][n];  
                          }  
                          }  
                          
                          //Redefining handlers array  
                          o[name] = newArray ;  
                          
                          },  
                          
                          //Checking if some event host a specific handler  
                          hasEventListener:function(name, handler) {  
                          var n;  
                          
                          if ( !o[name] || !(o[name] instanceof Array) || !o[name].length ) return false;  
                          
                          n = o[name].length;  
                          
                          //If handle is found, return true. Otherwise return false  
                          while ( n-- ) if ( o[name][n] === handler ) return true;  
                          
                          return false;  
                          },  
                          
                          //Some utility to get access to the handler array for some specific event or all the eventManager class  
                          expose:function(name){  
                          if ( name ) {  
                          if ( !o[name] || !(o[name] instanceof Array) || o[name.length] ) return "no events set";  
                          else return o[name].toSource();  
                          }  
                          else {  
                          return o.toSource();  
                          }  
                          }  
                          }  
                        }; 
                        
                        var main = function() {  
                          var ev = new EventManager(),  
                          u, actions = {};  
                          
                          var CBX = function(p, label, v, callback) {  
                            var cbx = p.add('checkbox', undefined, label); 
                            cbx.onClick = function() {
                                ev.dispatchEvent ( (cbx.value? "ADD_ACTION":"REMOVE_ACTION"), {label:label, callback:callback} );
                            }
                            return cbx;  
                          };  
                          
                          var w = new Window ('dialog','About CBX & EVENTS');  
                          var p1 = w.add('panel', u,'MAIN CBX');  
                          
                          new CBX ( p1, 'F/C 1', false, cb1CallBack );
                          new CBX ( p1, 'F/C 2', false, cb2CallBack );
                          
                          ev.addEventListener ( "ADD_ACTION", function(data) {
                                ev.actions = ev.actions || {};
                                ev.actions[data.label] = data.callback;
                          });
                        
                            ev.addEventListener ( "REMOVE_ACTION", function(data) {
                                if ( !ev.actions) return;
                                delete ev.actions[data.label];
                          });
                        
                        var btn = w.add('button',u, 'Run' );
                        btn.onClick = function () {
                            w.close(1);
                        }
                          
                            if ( w.show() == 1 && ev.actions) {
                                for ( prop in ev.actions ) {
                                    ev.actions[prop]();
                                }
                            }
                        }  
                          
                         function cb1CallBack() {
                            alert("That's a callback from cb1 call where you can F/C on docs"); 
                        }
                        
                         function cb2CallBack() {
                            alert("That's a callback from cb2 call where you can F/C on docs"); 
                        }
                        
                        main(); 
                        

                         

                        Capture d’écran 2016-06-21 à 00.36.47.png

                        Capture d’écran 2016-06-21 à 00.36.50.png

                         

                        HTH

                         

                        Loic

                        Ozalto | Productivity Oriented - Loïc Aigon

                        1 person found this helpful
                        • 9. Re: How to make this check box Apply to all Documents?
                          cbishop01 Level 2

                          I See whats going on here and it will work for what i'm wanting.   I'm just not sure how to add this to my script.  Here's how my script is layed out. from line 61-67 is the Check boxes the rest is there to show the structure i used.

                          var myResult;
                                  var w =new Window ('dialog {text: "Running Changes", orientation: "column", alignChildren:["fill","fill"],   properties:   {closeButton:   false}}');
                                  
                                      w.main =w.add ('group {preferredSize: [600, 600], alignChildren: ["left","fill"]}');
                                      w.stubs  = w.main.add ('listbox', undefined, ['About',  'GHS Changes', 'NON-GHS', 'Check for changes']); 
                                      w.stubs.preferredSize.width  = 120;  w.tabGroup  = w.main.add ('group {alignment: ["Fill","Fill"], orientation: "stack"}');
                          //~  1st Tab.           
                                      w.tabs  =[];
                                      w.tabs[0]= w.tabGroup.add ('group');
                                      w.tabs[0].add ('statictext {text: "About this script"}');
                                      w.tabs[0].add ('panel');
                                   with(w.tabs[0])  
                                      {  
                                 /*  with(add ('group {alignment: "center"}')){*/ 
                                       
                                      w.buttons  = w.add ('group {alignment: "right"}');
                                      exampleButton = w.buttons.add ('button {text: "EXAMPLES OF CHANGES"}');
                                  var Pan1=w.tabs[0].add ('panel {text: "THIS SCRIPT IS FOR!!", preferredSize: [-1, 200],orientation: "column",alignChildren: ["left","Center"]}');
                                     mL = Pan1.add("listbox", ["0", "0", "600", "600"]);
                            
                                  with (mL){
                              for (var i = 0; i < 1; i++)  
                                     // mL.add ("item", "List Item " + String (i))  
                                      mL.add ("item", " " )
                                      mL.add ("item", "Help Make Running Changes easer");
                                      mL.add ("item", "Automatically Correct Some changes");
                                      mL.add ("item", "Show What The running Changes are");
                                      mL.add ("item", "Help Make Running Changes easer");
                                      mL.add ("item", "Automatically Correct Some changes");
                                      mL.add ("item", "Show What The running Changes are");
                                      mL.add ("item", "Help Make Running Changes easer");
                                      mL.add ("item", "Automatically Correct Some changes");
                                      mL.add ("item", "Show What The running Changes are");
                                      mL.add ("item", "Help Make Running Changes easer");
                                      mL.add ("item", "Automatically Correct Some changes");
                                      mL.add ("item", "Show What The running Changes are");
                                      mL.add ("item", "Help Make Running Changes easer");
                                      mL.add ("item", "Automatically Correct Some changes");
                                      mL.add ("item", "Show What The running Changes are");
                                      mL.add ("item", "Help Make Running Changes easer");
                                      mL.add ("item", "Automatically Correct Some changes");
                                      mL.add ("item", "Show What The running Changes are");
                                      mL.revealItem (mL.items.length - i/1);  
                                  Pan1.show ()
                            
                            }            
                                      exampleButton.onClick = function ()     
                              {
                                  var  myFile = File ("/Users/Folks/Desktop/Blank Landscape[1].pdf");  
                                  if(myFile === null){exit()}; 
                                  myFile.execute("Blank Landscape[1].pdf")
                              }
                              }     
                            
                          
                          //~  2nd Tab              
                                      w.tabs[1]= w.tabGroup.add ('group');
                                      w.tabs[1].add('statictext {text: "Select a change to make"}');
                                      w.tabs[1].add ('panel');
                          //-----------------------------> Here's where the first set of Checkboxes are <-------------------------------------\\
                                    var RunCH1, RunCH2, RunCH3, RunCH6, ADOCS;
                               
                                     ADOCS= w.tabs[1].add ('checkbox {text: "APPLY TO ALL DOCUMENTS"}');
                                      RunCH1= w.tabs[1].add ('checkbox {text: "Find and Replace"}');
                                      RunCH2= w.tabs[1].add ('checkbox {text: "RQ and Bigger GHS Running Changes English / Spanish / French"}');
                                      RunCH3= w.tabs[1].add ('checkbox {text: "RP and Smaller GHS Running Changes English / Spanish"}');  
                                      RunCH6= w.tabs[1].add ('checkbox {text: "5 Galon weight Statement change to 18.924 Liters"}');
                                         
                              
                                 // var Pan1=w.tabs[1].add ('panel {text: "Find and Replace", preferredSize: [-1, 200],orientation: "column",alignChildren: ["left","Center"]}');
                                      var Pan1=w.tabs[1].add ('panel {text: "GHS!!", preferredSize: [-1, 200],orientation: "column",alignChildren: ["left","Center"]}');
                                     mL = Pan1.add("listbox", ["0", "0", "600", "600"]);
                            
                                  with (mL){
                              for (var i = 0; i < 1; i++)  
                                     // mL.add ("item", "List Item " + String (i))  
                                      mL.add ("item", "!!--->  FIND AND REPLACE <---!! " )
                          

                          And RunCH1,2,3,4,5 etc...  all are Find and replace different texts.  Here's an example of how they are coded as well in case you need it  too.

                           myResult = w.show(); 
                                
                                  if(myResult == 1 && (RunCH1.value==true)){      
                                      Replace_TXT(" <CR> ", "^p");    
                                      Replace_TXT(" <CR>", "^p");    
                                      Replace_TXT("  ", " ");    
                                      Replace_TXT(" :", ":");    
                                      Replace_TXT(" .", ".");    
                                      Replace_TXT("^p^p", "^p");    
                           }  
                                  if(myResult == 1 && (RunCH2.value==true ) ){ 
                                      Replace_TXT (""); 
                                      Replace_TXT ("");
                                      Replace_TXT ("");
                                      Replace_TXT ("");
                                      Replace_TXT ("");
                                      Replace_TXT ("");
                                      Replace_TXT ("");
                           }; 
                                  if(myResult == 1 && (RunCH3.value==true) ){ 
                                      Replace_TXT (""); 
                                      Replace_TXT ("");
                                      Replace_TXT ("");
                                      Replace_TXT ("");
                                      Replace_TXT ("");
                                      Replace_TXT ("");
                              }; 
                          
                                  if(myResult == 1 && (RunCH4.value==true) ){
                                      Replace_TXT ("");
                                      Replace_TXT ("");
                                      Replace_TXT ("");
                                      Replace_TXT ("");
                                      Replace_TXT ("");
                              
                            };  
                                   
                                  if(myResult == 1 && (RunCH5.value==true)){      
                                      Replace_TXT(" <CR> ", "^p");    
                                      Replace_TXT(" <CR>", "^p");    
                                      Replace_TXT("  ", " ");    
                                      Replace_TXT(" :", ":");    
                                      Replace_TXT(" .", ".");    
                                      Replace_TXT("^p^p", "^p");
                          
                          
                          
                          • 10. Re: How to make this check box Apply to all Documents?
                            cbishop01 Level 2

                            If you need to see the full code let me know and i'll paste it. 

                            • 11. Re: How to make this check box Apply to all Documents?
                              cbishop01 Level 2

                              Ok i've Gotten this to look for the most part. like my other Script.  However i cannot get the Find/replace to work now and Still cannot get apply to all documents either. I kept your Coding and am now trying to get the replace part to work.  After that it will be what i need.

                              Screen Shot 2016-06-21 at 2.58.34 PM.png

                               

                               

                                w.tabs[1]= w.tabGroup.add ('group');
                                w.tabs[1].add('statictext {text: "Select a change to make"}');
                                w.tabs[1].add ('panel');
                              with(w.tabs[1])
                              var p1 = w.tabs[1].add('panel {text: "CHANGES", preferredSize: [-1, 100],orientation: "column",alignChildren: ["left","Center"]}');
                                new CBX ( p1, 'APPLY TO ALL DOCUMENTS', false, cb1CallBack );
                                new CBX ( p1, 'Find and Replace', false, cb2CallBack );  
                                new CBX ( p1, 'RQ and Bigger GHS Running Changes English / Spanish / French', false, cb3CallBack );  
                                new CBX ( p1, 'RP and Smaller GHS Running Changes English / Spanish', false, cb4CallBack );  
                                new CBX ( p1, '5 Galon weight Statement change to 18.924 Liters', false, cb5CallBack );
                              
                              //Start of ListBox
                              var Pan1=w.tabs[1].add ('panel {text: "GHS!!", preferredSize: [-1, 100],orientation: "column",alignChildren: ["left","Center"]}');
                              
                              
                              

                               

                              And the search string i'm trying is. 

                               

                              myResult = w.show(); 
                                   
                              function cb1CallBack() {
                                  if(myResult == 1 && (cb1CallBack.value==true)){      
                                          Replace_TXT(" <CR> ", "^p");    
                                          Replace_TXT(" <CR>", "^p");    
                                          Replace_TXT("  ", " ");    
                                          Replace_TXT(" :", ":");    
                                          Replace_TXT(" .", ".");    
                                          Replace_TXT("^p^p", "^p");    
                               }  
                              } 
                                  function cb2CallBack() {}
                                  function cb3CallBack() {} 
                                  function cb4CallBack() {} 
                                  function cb5CallBack() {} 
                                  function cb5CallBack() {} 
                                  function cb6CallBack() {} 
                                  function cb7CallBack() {} 
                                  function cb8CallBack() {} 
                                  function cb9CallBack() {} 
                                  function cb10CallBack() {}  
                                  
                                  
                                  function Replace_TXT(input, output)      
                               {      
                                  app.findChangeTextOptions.caseSensitive = true;      
                                  app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;      
                                  app.findTextPreferences.findWhat = input;      
                                  app.changeTextPreferences.changeTo = output;      
                                  app.documents[0].changeText();      
                               } 
                              }
                                  main();
                              
                              • 12. Re: How to make this check box Apply to all Documents?
                                cbishop01 Level 2

                                Ok one more update.  GOt the FInd/replace to work.  I have to take it out of the function {}.  SO now i just need it to Apply to all documetns once that check box is selected and i'm pretty much done.  Oh and i do like the way this script handels Checkboxes.  it is cleaner and easier to manage.  SO thank you..

                                • 14. Re: How to make this check box Apply to all Documents?
                                  cbishop01 Level 2

                                  I cannot find how to make this apply button work for every document when its checked.  I've tried searching here to look for the coding but i'm not seeing it. Also.

                                   

                                  This did break one thing that i need.  It makes all my changes at once.  I only want it to make the changes of the selected Checkbox.  How can i do that with this code?  

                                  • 15. Re: How to make this check box Apply to all Documents?
                                    Loic.Aigon Adobe Community Professional

                                    I think I introduced this to you a bit sooner:

                                     

                                    The underlaying concept is to dispatch events when checkboxes are clicked. then you can use an object to store or remove any function that will need to be run later. Rather than checking every single checkbox status, you just loop through that objects and execute every single attached function.

                                     

                                    //add a listener so any event of type "ADD_ACTION" dispatched attach a function to the ev.actions object
                                    //while using the checkbox label as a key
                                    ev.addEventListener ( "ADD_ACTION", function(data) {  
                                            ev.actions = ev.actions || {};  
                                            ev.actions[data.label] = data.callback;  
                                      });  
                                    
                                    
                                      //add a listener so any event of type "REMOVE_ACTION" dispatched detach a function from the ev.actions object
                                    //while using the checkbox label as a key
                                        ev.addEventListener ( "REMOVE_ACTION", function(data) {  
                                            if ( !ev.actions) return;  
                                            delete ev.actions[data.label];  
                                      });  
                                     
                                    
                                    

                                     

                                    Then check box dispatch event based on its value

                                    var CBX = function(p, label, v, callback) {    
                                        var cbx = p.add('checkbox', undefined, label);   
                                        cbx.onClick = function() {  
                                      //Depending on the checkbox value
                                      //either a "ADD_ACTION" event or a "REMOVE_ACTION" event is fired 
                                            ev.dispatchEvent ( (cbx.value? "ADD_ACTION":"REMOVE_ACTION"), {label:label, callback:callback} );  
                                        }  
                                        return cbx;    
                                      }; 
                                    

                                     

                                     

                                    Eventually, you look at the ev.actions object and loop tjrough its properties which are mainly functions you can then call

                                    var btn = w.add('button',u, 'Run' );  
                                    btn.onClick = function () {  
                                        w.close(1);  
                                    }  
                                        
                                        if ( w.show() == 1 && ev.actions) {  
                                    
                                      //looping through all properties of the ev.actions object
                                      //which are functions
                                            for ( prop in ev.actions ) {  
                                                ev.actions[prop]();  
                                            }  
                                        }  
                                    } 
                                    

                                     

                                    This object can only be filled of functions related to checkboxes that have been checked on.

                                    1 person found this helpful
                                    • 16. Re: How to make this check box Apply to all Documents?
                                      cbishop01 Level 2

                                      Well Yes you did.  I forgot i shut off /* */ the top code you just posted to test another part of the script.  Check Boxes work now. MyBad

                                       

                                      Which one of these controls the "Apply all" CHeck BOX?  I have it with cb1CallBack.  Which i know the:

                                      function cb1CallBack(){}  //what would i put in the {}?
                                      

                                      i tried app.documents[0] and app.documents.everyItem() and it did not apply to all the documents.  So i'm guessing i have to add something. 

                                      • 17. Re: How to make this check box Apply to all Documents?
                                        Loic.Aigon Adobe Community Professional

                                        I would recommend this construction:

                                         

                                        function grep(findProps, changeProps) {
                                          app.findGrepPreferences = app.changeGrepPreferences.changeTo = null;
                                          app.findGrepPreferences.properties = findProps;
                                          app.changeGrepPreferences.properties = changeProps;
                                          app.changeGrep();
                                        }
                                        
                                        
                                        function cb1CallBack() {
                                          var findProps = {
                                          findWhat="\s{2, }",
                                          },
                                          changeProps = {
                                          findWhat=" ",
                                          };
                                        
                                        
                                          grep ( findProps, changeProps );
                                        }
                                        
                                        
                                        //etc.
                                        

                                         

                                         

                                        HTH

                                         

                                        Loic

                                        1 person found this helpful
                                        • 18. Re: How to make this check box Apply to all Documents?
                                          cbishop01 Level 2

                                          I'm getting an error on the equal sign in --->   findWhat="\s{2, }",   <----

                                          • 19. Re: How to make this check box Apply to all Documents?
                                            Loic.Aigon Adobe Community Professional

                                            typed too quick, it's a colon not an equal sign

                                            findWhat:"\s{2, }"

                                            1 person found this helpful
                                            • 20. Re: How to make this check box Apply to all Documents?
                                              cbishop01 Level 2

                                              I know little to nothing about grep.  What does this do?  When i activate it the Apply button does the changes to the documents and other than some s's being removed i'm not sure what all it does.  I only need the "Apply/cb1CallBack" CB to Apply to all documents if.

                                              cb1CallBack + cb2CallBack    OR      

                                              cb1CallBack + cb3CallBack    OR

                                              cb1CallBack + cb2CallBack + cb3CallBack etc...

                                              and if just the cb1CallBack is unchecked then cb2CallBack, cb3CallBack, etc... will only apply to the active document(which this is how it works now).

                                               

                                              BTW thank you for all your doing here.  I'm learning A TON.

                                              • 21. Re: How to make this check box Apply to all Documents?
                                                Loic.Aigon Adobe Community Professional

                                                Fixed some typos but basically your "all/none" checkbox is a modifier for the source object onto which call the changeGrep function.

                                                 

                                                Ok you have a lot of material now, so it's up to you now.

                                                 

                                                //Our Pseudo Event Class    
                                                var EventManager = function()    
                                                {    
                                                    
                                                  //Our internal key object    
                                                  var o  = {    
                                                    
                                                  };    
                                                    
                                                    
                                                  //return the Event Manager API    
                                                  return {    
                                                    
                                                  //Add a listener to the class for a specific event    
                                                  addEventListener:function(name, handler) {    
                                                    
                                                  //Return if the supplied handler already belongs to the listened event    
                                                  if ( this.hasEventListener (name, handler) ) return;    
                                                    
                                                  //Adding the handler for the event    
                                                  o[name] = o[name] || [];    
                                                  o[name][o[name].length]=handler;    
                                                    
                                                  },    
                                                    
                                                  //Executes every handler attached to the event    
                                                  //passing data as argument    
                                                  dispatchEvent:function(name, data) {    
                                                    
                                                  var n, i=0;     
                                                    
                                                  //Return if no handler is set    
                                                  if ( !o[name] || !(o[name] instanceof Array) || !o[name].length ) return;    
                                                    
                                                  n = o[name].length;    
                                                    
                                                  //executes every handler    
                                                  for ( i = 0; i<n; i++ ) {    
                                                  o[name][i](data);    
                                                  }    
                                                  },    
                                                    
                                                  //Remove a specific handler for the event    
                                                  removeEventListener:function(name, handler) {    
                                                    
                                                  //We will redefine the internal chain of handlers    
                                                  //passing the content of the "new" newArray array    
                                                  var newArray = [], n;    
                                                    
                                                  //Return if no handler is set    
                                                  if ( !this.hasEventListener ( name, handler ) ) return;    
                                                    
                                                  n = o[name].length;    
                                                    
                                                  //Storing handlers into newArray if different from specific handler    
                                                  while ( n-- ) {    
                                                  if ( (o[name][n] !== handler) ) {    
                                                  newArray [ newArray.length ] = o[name][n];    
                                                  }    
                                                  }    
                                                    
                                                  //Redefining handlers array    
                                                  o[name] = newArray ;    
                                                    
                                                  },    
                                                    
                                                  //Checking if some event host a specific handler    
                                                  hasEventListener:function(name, handler) {    
                                                  var n;    
                                                    
                                                  if ( !o[name] || !(o[name] instanceof Array) || !o[name].length ) return false;    
                                                    
                                                  n = o[name].length;    
                                                    
                                                  //If handle is found, return true. Otherwise return false    
                                                  while ( n-- ) if ( o[name][n] === handler ) return true;    
                                                    
                                                  return false;    
                                                  },    
                                                    
                                                  //Some utility to get access to the handler array for some specific event or all the eventManager class    
                                                  expose:function(name){    
                                                  if ( name ) {    
                                                  if ( !o[name] || !(o[name] instanceof Array) || o[name.length] ) return "no events set";    
                                                  else return o[name].toSource();    
                                                  }    
                                                  else {    
                                                  return o.toSource();    
                                                  }    
                                                  }    
                                                  }    
                                                }; 
                                                
                                                
                                                
                                                
                                                
                                                
                                                var main = function() {    
                                                  var ev = new EventManager(),    
                                                  u, actions = {};
                                                  var CBX = function(p, label, v, callback) {    
                                                  var cbx = p.add('checkbox', undefined, label);   
                                                  cbx.onClick = function() {  
                                                  ev.dispatchEvent ( (cbx.value? "ADD_ACTION":"REMOVE_ACTION"), {label:label, callback:callback} );  
                                                  }  
                                                  return cbx;    
                                                  };  
                                                
                                                
                                                  var w = new Window ('dialog','About CBX & EVENTS');    
                                                  var p1 = w.add('panel', u,'MAIN CBX');    
                                                
                                                  new CBX ( p1, 'F/C 1', false, cb1CallBack ); 
                                                
                                                  //adding main checkbox that once click will dispatch the "DEFINE_TARGET" event
                                                  var mainCbx = w.add('checkbox',undefined, 'Apply to all documents');
                                                  mainCbx.onClick = function() {
                                                  ev.dispatchEvent ( "DEFINE_TARGET", mainCbx.value );
                                                  }
                                                
                                                
                                                  var btn = w.add('button',u, 'Run' );    
                                                  btn.onClick = function () {    
                                                  w.close(1);    
                                                  }    
                                                
                                                  ev.addEventListener ( "ADD_ACTION", function(data) {  
                                                  ev.actions = ev.actions || {};  
                                                  ev.actions[data.label] = data.callback;  
                                                  });  
                                                  
                                                  ev.addEventListener ( "REMOVE_ACTION", function(data) {  
                                                  if ( !ev.actions) return;  
                                                  delete ev.actions[data.label];  
                                                  });  
                                                
                                                  ev.target = app.properties.activeDocument;
                                                
                                                  //add a listener so any event of type "DEFINE_TARGET" dispatched set ev.target value;
                                                  ev.addEventListener ( "DEFINE_TARGET", function(data) {   
                                                
                                                  ev.target = data? app : app.properties.activeDocument;
                                                  });
                                                
                                                
                                                  if ( w.show() == 1 && ev.actions) {    
                                                  
                                                  //looping through all properties of the ev.actions object  
                                                  //which are functions  
                                                  
                                                  for ( prop in ev.actions ) {    
                                                  ev.actions[prop](ev.target);    
                                                  }    
                                                  }    
                                                } 
                                                
                                                
                                                
                                                
                                                
                                                
                                                function grep(target, findProps, changeProps) {  
                                                  app.findGrepPreferences = app.changeGrepPreferences = null;  
                                                  app.findGrepPreferences.properties = findProps;  
                                                  app.changeGrepPreferences.properties = changeProps;  
                                                  target.changeGrep();  
                                                }  
                                                  
                                                  
                                                function cb1CallBack(target) {  
                                                
                                                  var findProps = {  
                                                  findWhat:"\\s{2, }",  
                                                  },  
                                                  changeProps = {  
                                                  changeTo:" ",  
                                                  };  
                                                  
                                                  
                                                  grep (target,  findProps, changeProps );  
                                                }  
                                                
                                                
                                                if ( !app.properties.activeDocument ) {
                                                  alert('you need an open document at least');
                                                }
                                                else {
                                                  main();
                                                }
                                                
                                                
                                                  
                                                    
                                                  
                                                
                                                
                                                
                                                
                                                1 person found this helpful
                                                • 22. Re: How to make this check box Apply to all Documents?
                                                  cbishop01 Level 2

                                                  I'll tinker with it tomorrow.  Thank you so very much for the time you spend on helping me. 

                                                  • 23. Re: How to make this check box Apply to all Documents?
                                                    cbishop01 Level 2

                                                    This is working like a charm.  it took me a min to figure out how to Find/ Change Text as well as Grep on all documents but It seems to be working.  Thanks again.