8 Replies Latest reply on Aug 23, 2014 7:04 AM by [Jongware]

    clear pasteboard with alert (yes or no)

    AsOne Level 1

      Hi All,

       

      I am trying to clear pasteboard with yes or no alert, script running without error but not functioning

      What my error, any help ?

       

      //Pasteboard Clean
      confirm("Do you want to Clean PasteBoard?");
      if (confirm.window==true) function removePasteboardItems() {
      
      removePasteboardItems(app.documents.length && app.activeDocument);  
      function removePasteboardItems(/*?Document*/doc) {  
          if( !doc ) return;  
          var items = doc.pageItems.everyItem().getElements(),  
              t = null;  
          while( t=items.pop() ) t.parentPage || removeItem(t);  
          t = items = null;  
      }
      function removeItem(/*PageItem*/item)  
      {  
          try {  
              item.locked = false;  
              item.remove();  
              }  
          catch(_){}  
      }  
      }else  {
          exit();
          }
      

       

      Thanks in advance

      Steve

        • 1. Re: clear pasteboard with alert (yes or no)
          BEGINNER_X Level 3

          Hi Steve,

           

          Please edit the below code as per your request.

           

          var myDoc = app.activeDocument;
          
          var myPageItems = myDoc.allPageItems
          
          for(i=0; i<myPageItems.length; i++)
          {
              if(myPageItems[i].parentPage == null)
              {
                  myPageItems[i].locked = false;
                  app.select(myPageItems[i])
                  alert("PasteBoard Items are available");
                          
                  var check = confirm("Do you want to continue\n")
                   if (check == true){
                     continue;
                      } 
                    else{
                     exit(0);
                     }
                  }
              }
          
          

           

           

          Regards

          Siraj

          1 person found this helpful
          • 2. Re: clear pasteboard with alert (yes or no)
            AsOne Level 1

            Hi Siraj, The method of parentPage not working Thanks Steve

            • 3. Re: clear pasteboard with alert (yes or no)
              BEGINNER_X Level 3

              Hi Steve,

               

              parentPage concept working on CS5 and above version.

               

              Let me know your version.

              • 4. Re: clear pasteboard with alert (yes or no)
                AsOne Level 1

                Hi Siraj, CS6 (8.0) Steve

                • 5. Re: clear pasteboard with alert (yes or no)
                  Obi-wan Kenobi Adobe Community Professional

                  Hi,

                   

                  Marc Autret has written CleanupPasteboard.jsx in March 2009. It still works today … with ID CC 2014 !!!!! 

                   

                  Indiscripts :: Nettoyer la table de montage

                   

                  Image 32.png

                  • 6. Re: clear pasteboard with alert (yes or no)
                    Marc Autret Level 4

                    Merci Obi-wan

                    Thanks for the mention.

                     

                    @+

                    Marc

                    • 7. Re: Re: clear pasteboard with alert (yes or no)
                      Laubender Adobe Community Professional & MVP

                      @Steve – "not working" is no problem discription.

                       

                      Siraj's script is working.

                       

                      The problem with it: what does it do? What is it supposed to do?
                      That means: it might not meet your expectations. Why? Because Siraj did not explicitly voice what it will do. And you expected a solution to your original problem.

                       

                      To discuss what is your expectation (on your side) and the one who is suggesting something (run that code, dude!) is a bit, er, rudimentary here:

                       

                       

                      OP: I want the following, here my code.

                      HELPER: Run the following code!
                      OP: Does not work!

                       

                      Away from this.
                      Back to your code…

                       

                      For me reading this it is a bit convoluted.
                      But what is the main problem: Your "confirm" always generates "No". Never "Yes". Always the "else" that leads to exit().

                       

                      Try running the following. What will be the result in the JavaScript console of the ESTK?

                       

                      confirm("Do you want to Clean PasteBoard?");
                      
                      if(confirm.window==true){  
                          removePasteboardItems(app.activeDocument);
                          $.writeln("CONFIRMED YES!");
                          };
                      else{
                          $.writeln("CONFIRMED No! Exit now.");
                          exit();
                          };
                      
                      function removePasteboardItems(doc){
                          $.writeln("TRYING TO DO SOMETHING ON: "+doc.name);
                          };
                      

                       

                      Opposed to the following:

                       

                      var myResult = confirm("Do you want to Clean PasteBoard?");
                      
                      if(myResult){
                          $.writeln("CONFIRMED YES!");
                          removePasteboardItems(app.activeDocument);
                          };
                      else{
                          $.writeln("CONFIRMED No! Will exit now.");
                          exit();
                          };
                      
                      function removePasteboardItems(doc){
                          $.writeln("TRYING TO DO SOMETHING ON: "+doc.name);
                          };
                      

                       

                      Now we can add your version of removePasteboardItems(doc) and function removeItem() and the thing should run.

                       

                      var myResult = confirm("Do you want to Clean PasteBoard?");
                      
                      if(myResult){
                          //$.writeln("CONFIRMED YES!");
                          removePasteboardItems(app.activeDocument);
                          };
                      else{
                          //$.writeln("CONFIRMED No! Will exit now.");
                          exit();
                          };
                      
                      //~ function removePasteboardItems(doc){
                      //~     $.writeln("TRYING TO DO SOMETHING ON: "+doc.name);
                      //~     };
                      
                      function removePasteboardItems(/*?Document*/doc) {    
                          if( !doc ) return;
                          
                          var items = doc.pageItems.everyItem().getElements(),    
                          t = null;
                          
                          while( t=items.pop() ) t.parentPage || removeItem(t);    
                          t = items = null;
                          
                          };
                      
                      function removeItem(/*PageItem*/item){    
                          try {    
                              item.locked = false;    
                              item.remove();    
                              }    
                          catch(_){};
                          };
                      

                       

                      I commented out the lines with $.writeln() and my dummy function.

                      Instead of app.activeDocument you could widen the scope to app.documents.everyItem() for every open document.

                      But first try and test with one single document.

                       

                      Uwe

                      • 8. Re: clear pasteboard with alert (yes or no)
                        [Jongware] Most Valuable Participant

                        Yup - a basic logic error. The function 'confirm'  has no 'window' property, and even if it did, the code would still not work correctly.

                         

                        The statement "if (confirm.window==true") first checks if 'confirm' has a .window property, and if it does, it returns the value of that. Suppose it does; you would get a 'window' back. Is this equal to 'true'? No, it's a window, and no matter what further data it may have, it's never simply "true" or "false".

                         

                        For 'confirm' the opposite is the case: "confirm.window" does not exist, and so it returns 'undefined'. Is 'undefined' equal to "true"? Nope. (Note that 'undefined' may be equal to 'false', but that is another discussion, and not purely related to InDesign scripting.)

                         

                        So the shown code would not work anyway. Lesson: do not write Frankenstein code, attempting to paste together "likely" parts and bits, and hope it magically works. Look up "cargo cult programming" for more on this.

                         

                        The catch is that Javascript is very fault-tolerant. In stricter programming languages, attempting to access a non-existing property would show and error, but JS does not.