12 Replies Latest reply on May 9, 2016 9:50 AM by cbishop01

    Apply Button?

    cbishop01 Level 2

      I've been messing with this for way too long.  How do you make an apply button work on a scrtip?  below is what i have and it shows up but does not work.    

       w.buttons  = w.add ('group {alignment: "right"}');
       w.buttons.add  ('button {text: "Apply"}');// this one shows up but does not work
       w.add ("button", undefined, "Apply");// same with this one.
       w.buttons.add  ('button {text: "OK"}');
       w.buttons.add  ('button {text: "Cancel"}');
      

      The Ok and Cancel buttons work fine.  I cannot make any of the APPLY buttons just apply the changes from my check boxes i have. 

       

      Thanks in advance.

        • 1. Re: Apply Button?
          Peter Spier Most Valuable Participant (Moderator)

          I've moved this into the scripting forum...

          • 2. Re: Apply Button?
            Peter Kahrel Adobe Community Professional & MVP

            Buttons with the text OK and Cancel work by default in response to the Return and Esc keys. For any other button you have to specify what should happen when they're clicked:

             

            applyButton = w.buttons.add  ('button {text: "Apply"}');
            . . .
            applyButton.onClick = function () {
              // do something
            }
            

             

            Peter

            1 person found this helpful
            • 3. Re: Apply Button?
              cbishop01 Level 2

              what would the function to apply be?  I'm a super novice at programming.  also the ... gives me an error.  I'm wanting this apply button to activate the Checkboxes i have.   if you need the rest of the code here to help you out let me know and i'll put whatever you need on here.  thank you

              • 4. Re: Apply Button?
                Peter Kahrel Adobe Community Professional & MVP

                > what would the function to apply be?

                 

                Whatever you want it to be/do.

                 

                > the ... gives me an error.

                 

                The ellipsis was just to indicate 'more code', used in the sense of points of omission -- not points of suspension, as it were. You shouldn't use it like that in a script. . .

                1 person found this helpful
                • 5. Re: Apply Button?
                  cbishop01 Level 2

                  The Apply button would activate the RunCH1, 2 and 3 on line 19-21.  The search strings to activate start on 156

                       
                      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, ['Changes',  'Check For Changes', 'Example']); 
                          w.stubs.preferredSize.width  = 120;  w.tabGroup  = w.main.add ('group {alignment: ["Fill","Fill"], orientation: "stack"}');
                              w.tabs  =[];
                                  w.tabs[0]= w.tabGroup.add ('group');
                                  w.tabs[0].add('statictext {text: ""}');
                              w.tabs  =[];
                                  w.tabs[0]= w.tabGroup.add ('group');
                                  w.tabs[0].add('statictext {text: "Select a change to make"}');
                              w.tabs[0].add ('panel');
                       
                  
                  
                          var RunCH1= w.tabs[0].add ('checkbox {text: "Find and Replace"}');
                          var RunCH2= w.tabs[0].add ('checkbox {text: "GHS Running Changes"}');
                          var RunCH3= w.tabs[0].add ('checkbox {text: "Non-GHS Running Changes"}');       
                           
                                   
                                   var Pan1=w.tabs[0].add ('panel {text: "Find and Replace", preferredSize: [-1, 200],orientation: "column",alignChildren: ["left","Center"]}');
                                
                                      Pan1.add('statictext {text: "Double Space   -   Single Space"}');
                                      Pan1.add('statictext {text: "Space :    -   :"}');
                                      Pan1.add('statictext {text: "Space .    -   ."}');
                                      Pan1.add('statictext {text: "<CR>   -   Return"}');
                                      Pan1.add('statictext {text: "Double Return  -   Return"}');
                                         
                                  
                                   var Pan1=w.tabs[0].add ('panel {text: "GHS Running Changes", preferredSize: [-1, 150],orientation: "column",alignChildren: ["left","Center`"]}');
                                 
                                      Pan1.add('statictext {text: "B1.   Enter Here1"}');
                                      Pan1.add('statictext {text: "B2.   Enter Here2"}');
                                      Pan1.add('statictext {text: "B3.   Enter Here3"}');
                                      Pan1.add('statictext {text: "B4.   Enter Here4"}');
                               
                               
                                
                                  var Pan1=w.tabs[0].add ('panel {text: "Non-GHS Running Changes", preferredSize: [-1, 150],orientation: "column",alignChildren: ["left","Center`"]}');
                                 
                                      Pan1.add('statictext {text: "B1.   Enter Here5"}');
                                      Pan1.add('statictext {text: "B2.   Enter Here6"}');
                                      Pan1.add('statictext {text: "B3.   Enter Here7"}');
                                      Pan1.add('statictext {text: "B4.   Enter Here8"}');
                       
                                   var Pan1=w.tabs[0].add ('panel {text: "Contact Infromation", preferredSize: [-1, 62],orientation: "column",alignChildren: ["left","Center`"]}');
                                 
                  
                  
                                      Pan1.add('statictext {text: "*email Address here*"}');
                                     
                               
                       
                          with(w.tabs[0])
                          {
                          with(add ('group {alignment: "left"}'))
                          {
                                         add ('button {text: "Reset all warning dialogs"}');
                          }
                          }
                              w.tabs[1]= w.tabGroup.add ('group');
                              w.tabs[1].add ('statictext {text: "Changes that WILL need checked"}');
                              w.tabs[1].add ('panel {preferredSize: [-1, -10]}');
                              var Pan1=w.tabs[1].add ('panel {text: "GHS", preferredSize: [-1, 250],orientation: "column",alignChildren: ["left","Center`"]}');
                                 
                                      Pan1.add('statictext {text: "B1.   Here"}');
                                      Pan1.add('statictext {text: "B2.   Here"}');
                                      Pan1.add('statictext {text: "B3.   Here"}');
                                      Pan1.add('statictext {text: "B4.   Here"}');
                                      Pan1.add('statictext {text: "B5.   Here"}');
                                      Pan1.add('statictext {text: "G1.   Here"}');
                                      Pan1.add('statictext {text: "G2.   Here"}');
                                           
                              w.tabs[1].add ('panel {text: "Non-GHS", preferredSize: [-1, 100]}');
                              w.tabs[2]= w.tabGroup.add ('group');
                              w.tabs[2].add ('statictext {text: "Example Of running Changes"}');
                              w.tabs[2].add ('panel');
                              w.tabs[2].add ('statictext {text: "", preferredSize: [-1, 20]}');
                            
                        // How can i make PreV1 activate the below Radio buttons?  Maybe gray out the Buttons when not the Check box is not checked.
                       
                              var PreV1= w.tabs[2].add ('checkbox {text: "To Preview Changes"}');
                              var Pan1=w.tabs[2].add ('panel {text: "", preferredSize: [-1, 200],orientation: "column",alignChildren: ["left","top"]}');
                            
                        // Is there a way to make each radio button display a Different Pictrue?        
                       
                                      Pan1.add('radioButton {text: "B1.   Enter Here1"}');
                                      Pan1.add('radioButton {text: "B2.   Enter Here2"}');
                                      Pan1.add('radioButton {text: "B3.   Enter Here3"}');
                                      Pan1.add('radioButton {text: "B4.   Enter Here4"}');
                                      Pan1.add('radioButton {text: "B1.   Enter Here5"}');
                                      Pan1.add('radioButton {text: "B2.   Enter Here6"}');
                                      Pan1.add('radioButton {text: "B3.   Enter Here7"}');
                                      Pan1.add('radioButton {text: "B4.   Enter Here8"}');
                         /*
                       
                                 Image.prototype.onDraw =function()
                                  {
                                  if(!this.image )return;
                                  var WH =this.size,wh   =this.image.size,k   = Math.min(WH[0]/wh[0], WH[1]/wh[1]), xy;
                                    wh   =[k*wh[0],k*wh[1]];
                                    xy   =[(WH[0]-wh[0])/2, (WH[1]-wh[1])/2 ];
                                  this.graphics.drawImage(this.image,xy[0],xy[1],wh[0],wh[1]);
                                     WH   = wh = xy =null;
                                  }
                                 flower=w.tabs[2].add ("image", undefined, File ("~/\Desktop/\xxx.jpg"));
                                 flower.size =[300,300];
                            */   
                       
                     // I cannot seem to get this Apply button to work
                     
                                  w.buttons  = w.add ('group {alignment: "right"}');
                                  applyButton = w.buttons.add ('button {text: "Apply"}');
                                  applyButton.onClick = function () {
                                     applySelection     
                                          }
                                  w.buttons.add  ('button {text: "OK"}');
                                  w.buttons.add  ('button {text: "Cancel"}');
                          
                          for(
                          var i = 0;
                           i < w.tabs.length;
                           i++){
                          w.tabs[i].orientation ='column';
                          w.tabs[i].alignChildren ='fill';
                          w.tabs[i].alignment =['fill','fill'];
                          w.tabs[i].visible =false;
                          }
                          w.stubs.onChange  = showTab;
                          function
                           showTab ()
                          {
                          if(w.stubs.selection !==null){for(var i = w.tabs.length-1; i >= 0;
                           i--)
                           {    
                               w.tabs[i].visible =false;
                          }
                                   w.tabs[w.stubs.selection.index].visible =true;
                          }
                          }
                            w.onShow  =function()
                          {
                          w.stubs.selection  = 1;
                          showTab;
                          }
                       
                       
                      myResult = w.show(); 
                       
                      // How do i make each CHECK BOX RunCH1/2/3 Only work when they are selected?  I cannot figure out how to make 2&3 Work.
                  
                  
                          if(myResult == 1 && (RunCH1.value==true || RunCH2.value==true || RunCH3.value==true) ){  
                              alert("Find and Replace Items Have been made.!")
                                  Replace_TXT(" <CR> ", "^p");
                                  Replace_TXT(" <CR>", "^p");
                                  Replace_TXT("  ", " ");
                                  Replace_TXT(" :", ":");
                                  Replace_TXT(" .", ".");
                                  Replace_TXT("^p^p", "^p");
                                  
                                 
                                
                              if(myResult == 2 && (RunCH2.value==true ) );
                             
                                  Replace_TXT ("test", "asdfasdfasdfadsfasdfasdfasdfadfasdfasdf"); 
                                      
                           {  
                                      alert ("GHS Changes Made")  
                           }; 
                       
                              if(myResult == 3 && (RunCH3.value==true) ){  
                                  Replace_TXT("and", "TEST");
                            }  
                                     alert ("NON-GHS Changes Made")  
                            }; 
                              w.close(true);     
                      
                       
                      function Replace_TXT(input, output)  
                      {  
                      app.findChangeTextOptions.caseSensitive = true;  
                      app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;  
                      app.findTextPreferences.findWhat = input;  
                      app.changeTextPreferences.changeTo = output;  
                      app.activeDocument.changeText();  
                      }
                  
                  • 6. Re: Apply Button?
                    Peter Kahrel Adobe Community Professional & MVP

                    > The Apply button would activate the RunCH1, 2 and 3

                     

                    I guess you mean that the user ticks any of the three checkboxes and that when they click Apply, the script executes the actions associated with the ticked checkboxes. Correct? You need a palette-type window for that, not a dialog.

                     

                    applyButton.onClick = function () { 
                      if (RunCH1.value==true) {
                        // . . . 
                      }
                      if (RunCH2.value==true) {
                        // . . . 
                      }
                    
                      if (RunCH3.value==true) {
                        // . . . 
                      }
                    }
                    

                     

                    If you do want to use a dialog you need to create an object with the window's options and return that object. Your script then processes that object.

                     

                    Peter

                    1 person found this helpful
                    • 7. Re: Apply Button?
                      cbishop01 Level 2

                      I think i miss spoke.  The script above has a UI and Tabs.  on the 1st tab it has 3 check boxes and i was wanting the apply to activate the Search/Replace that i have set for those 3 check boxes when the check box is active.  I'm going to try and play around with this code you pasted and see if i can get it to work.  Again i am a novice so i may need more help.  I'll keep you posted.  thanks for your help.

                      • 8. Re: Apply Button?
                        cbishop01 Level 2

                        Ok what am i doing wrong?  I've added this into my button and i can get the apply to work(only with the alert)  If i put the search code in it does nothing.  and now my cancel button runs all the scripts.  Where did i go wrong?  I've tried about 6 different ways to put the replace_TXT in there but it does not work.  I left the last 3 ways i tried in there so you can tell me if i'm on the right path. 

                         

                        // I cannot seem to get this Apply button to work
                           
                                        w.buttons  = w.add ('group {alignment: "right"}');
                                        applyButton = w.buttons.add ('button {text: "Apply"}');
                                        applyButton.onClick = function () {
                                        if(RunCH1.value==true){ 
                                            Replace_TXT(" <CR> ", "^p");
                                            Replace_TXT(" <CR>", "^p");
                                            Replace_TXT("  ", " ");
                                            Replace_TXT(" :", ":");
                                            Replace_TXT(" .", ".");
                                            Replace_TXT("^p^p", "^p");
                                        
                                        alert ("Find and replace Done") 
                                      }         
                                        if(myResult == 2 && (RunCH2.value==true )){
                                            Replace_TXT ("test", "asdfasdfasdfadsfasdfasdfasdfadfasdfasdf"); 
                                            alert ("GHS Changes Made") 
                                            
                                      }          
                                        if(RunCH3.value==true){
                                           if(myResult == 3) ; 
                                        Replace_TXT("and", "TEST"); 
                                            alert ("Non-GHS Changes Made") 
                                      }      
                                   }
                                        w.buttons.add  ('button {text: "OK"}');
                                        w.buttons.add  ('button {text: "Cancel"}');
                                
                                for(
                                var i = 0;
                                 i < w.tabs.length;
                                 i++){
                                w.tabs[i].orientation ='column';
                                w.tabs[i].alignChildren ='fill';
                                w.tabs[i].alignment =['fill','fill'];
                                w.tabs[i].visible =false;
                                }
                                w.stubs.onChange  = showTab;
                                function
                                 showTab ()
                                {
                                if(w.stubs.selection !==null){for(var i = w.tabs.length-1; i >= 0;
                                 i--)
                                 {    
                                     w.tabs[i].visible =false;
                                }
                                         w.tabs[w.stubs.selection.index].visible =true;
                                }
                                }
                                  w.onShow  =function()
                                {
                                w.stubs.selection  = 1;
                                showTab;
                                }
                             
                             
                            myResult = w.show(); 
                             
                         // How do i make each CHECK BOX RunCH1/2/3 Only work when they are selected?  I cannot figure out how to make 2&3 Work.
                            
                                if(myResult == 1 && (RunCH1.value==true));  
                                    alert("Find and Replace Items Have been made.!");
                                        Replace_TXT(" <CR> ", "^p");
                                        Replace_TXT(" <CR>", "^p");
                                        Replace_TXT("  ", " ");
                                        Replace_TXT(" :", ":");
                                        Replace_TXT(" .", ".");
                                        Replace_TXT("^p^p", "^p");
                        
                                      
                                    if(myResult == 2 && (RunCH2.value==true ) );
                                   
                                        Replace_TXT ("test", "asdfasdfasdfadsfasdfasdfasdfadfasdfasdf"); 
                                            
                                    
                                    if(myResult == 3 && (RunCH3.value==true) ); 
                                        Replace_TXT("and", "TEST");
                                 
                                    w.close(true);     
                            
                             
                            function Replace_TXT(input, output)  
                            {  
                            app.findChangeTextOptions.caseSensitive = true;  
                            app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;  
                            app.findTextPreferences.findWhat = input;  
                            app.changeTextPreferences.changeTo = output;  
                            app.activeDocument.changeText();  
                            }
                        
                        • 9. Re: Apply Button?
                          Peter Kahrel Adobe Community Professional & MVP

                          As I mentioned in comment 6, you can't do this with a dialog-type window: if you ant the script to do the replacements while the dialog remains on your screen, you have to use a palette-type window.

                           

                          if(myResult == 1
                          if(myResult == 2
                          if(myResult == 3

                           

                          myResult is 1 (for OK) or 2 (for Cancel). That's it.

                           

                          > How do i make each CHECK BOX RunCH1/2/3 Only work when they are selected?

                          See the sample code in comment 6.

                           

                          If you're struggling with the logistics of a script, and especially if, as you say, you're a novice, you should start with a simple dialog. Once that works, you can expand it to its full envisaged complexity. You code is so complex that it's not easy for you to see where things go wrong.

                           

                          P.

                          1 person found this helpful
                          • 10. Re: Apply Button?
                            cbishop01 Level 2

                            AH so the myResult works different than i though.  And your Apply Button Did work.  I was using the wrong script in indesgn.  I forgot to save over my old script.  THe only thing i'm having trouble with is the Cancel button shows my alert message.  I am for now going to move on from the apply button and add functions that i know we will use and hold off on the functions that i at this point dont need.  Thank you for all your help. 

                            • 11. Re: Apply Button?
                              cbishop01 Level 2

                              This was because i had my Alert outside the last {}

                              • 12. Re: Apply Button?
                                cbishop01 Level 2

                                During my testing of the script I've actually came across a few reason i will need this Apply button to work.  I don't need any alerts/messages but how can i make it work?  this is the code i am wanting to work

                                 

                                applyButton = w.buttons.add ('button {text: "Apply"}')

                                                applyButton.onClick = function (){

                                                   

                                                   if(RunCH1.value==true)    

                                                    Replace_TXT(" <CR> ", "^p");   

                                                    Replace_TXT(" <CR>", "^p");   

                                                    Replace_TXT("  ", " ");   

                                                    Replace_TXT(" :", ":");   

                                                    Replace_TXT(" .", ".");   

                                                    Replace_TXT("^p^p", "^p");

                                            }

                                       

                                I already have that search string down lower on the code but that is the part i want to apply.  the other parts of the code dont need to be added to the apply.