13 Replies Latest reply on Jul 26, 2014 6:18 AM by Teetan VK

    Why the alert massage return twice on the screen?

    Teetan VK Level 1

      Hi, everyone

       

      I got this script:

       

      var

        mySelected = Number( app.extractLabel("mDialog") ),

        myDialog = app.dialogs.add({name:"Colse files save \"Yes\" or \"No\"",canCancel:true});

        with(myDialog){

             with(dialogColumns.add()){

                  with(dialogRows.add()){

                       var

                       mySelection = dropdowns.add({stringList:["01   Yes", "02   No", "03   Reverse"], selectedIndex: 0});

                  }

             }

        }

       

      if (myDialog.show() == true)

          main();

      myDialog.destroy();

       

      function main(){

            colse_file();

      }

       

      function colse_file(){

          if (mySelection.selectedIndex == 0){

      var docs = app.documents;

          for (var i = docs.length-1; i >= 0; i--) {

              docs[i].close(SaveOptions.YES);

      }

      alert("Done.\rAll files are saved.");

      }

       

          if (mySelection.selectedIndex == 1){

          var docs = app.documents;

          for (var i = docs.length-1; i >= 0; i--) {

              docs[i].close(SaveOptions.NO);

      }

      alert("Done.\rAll files are closed without save.");

      }

       

         if (mySelection.selectedIndex == 2){

      var docs = app.documents;

      app.scriptPreferences.userInteractionLevel = UserInteractionLevels.neverInteract;

      app.documents.everyItem().revert();

      app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;

      }

      alert("Done.\rAll files are reversed.");

      }

       

       

      Why the alert massage return twice on the screen?


       

      VK

        • 1. Re: Why the alert massage return twice on the screen?
          Chinnadk Level 4

          Hi VK,

           

          alert("Done.\rAll files are reversed.");

          Place this line into the "if condition" it is lying outside the "if condition" that why it returns alert twice

          • 2. Re: Why the alert massage return twice on the screen?
            Teetan VK Level 1

            Hi, Chinna

             

            I changed it into this:

             

            var

             

              mySelected = Number( app.extractLabel("mDialog") ),

             

              myDialog = app.dialogs.add({name:"Colse files save \"Yes\" or \"No\"",canCancel:true});

             

              with(myDialog){

             

                   with(dialogColumns.add()){

             

                        with(dialogRows.add()){

             

                             var

             

                             mySelection = dropdowns.add({stringList:["01   Yes", "02   No", "03   Reverse"], selectedIndex: 0});

             

                        }

             

                   }

             

              }

             

             

             

            if (myDialog.show() == true)

             

                main();

             

            myDialog.destroy();

             

             

             

            function main(){

             

                  colse_file();

             

            }

             

             

             

            function colse_file(){

             

                if (mySelection.selectedIndex == 0){

             

            var docs = app.documents;

             

                for (var i = docs.length-1; i >= 0; i--) {

             

                    docs[i].close(SaveOptions.YES);

            alert("Done.\rAll files are saved.");

             

            }

            }

             

             

             

                if (mySelection.selectedIndex == 1){

             

                var docs = app.documents;

             

                for (var i = docs.length-1; i >= 0; i--) {

             

                    docs[i].close(SaveOptions.NO);

            alert("Done.\rAll files are closed without save.");

             

            }

             

             

            }

             

             

             

               if (mySelection.selectedIndex == 2){

             

            var docs = app.documents;

             

            app.scriptPreferences.userInteractionLevel = UserInteractionLevels.neverInteract;

             

            app.documents.everyItem().revert();

             

            app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;

            alert("Done.\rAll files are reversed.");

             

            }

            }

             

            but I still got twice

             

            VK

            • 3. Re: Why the alert massage return twice on the screen?
              Chinnadk Level 4

              It is working fine here check again.

              • 4. Re: Why the alert massage return twice on the screen?
                Teetan VK Level 1

                even worse, close every file got once on screen.

                • 5. Re: Why the alert massage return twice on the screen?
                  Jump_Over Level 5

                  Hi,

                   

                  Even worse - you can see them as many times as many doc are opened - notice a differences between your 1st and 2nd code.

                  Are you writing them online?

                  Your alerts are inside for...loop now.

                   

                  Jarek

                  • 6. Re: Why the alert massage return twice on the screen?
                    Sajeev Sridharan Level 4

                    Hi,

                     

                    Dont change anything in your script, just replace last three lines:

                     

                    app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;

                    }

                    alert("Done.\rAll files are reversed.");

                    }

                     

                    Vandy

                    • 7. Re: Why the alert massage return twice on the screen?
                      Teetan VK Level 1

                      so what is the solution to fix it?

                      • 8. Re: Why the alert massage return twice on the screen?
                        Sajeev Sridharan Level 4

                        place the last alert message inside the closing curly brackets,

                         

                        Like below:

                         

                        app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;

                        alert("Done.\rAll files are reversed.");

                        }

                        }

                         

                        Vandy

                        • 9. Re: Why the alert massage return twice on the screen?
                          Teetan VK Level 1

                          Hi, Vandy

                           

                          I want three alerts for each function

                           

                          no just one

                           

                          thanks

                           

                          VK

                          • 10. Re: Re: Why the alert massage return twice on the screen?
                            pixxxel schubser Level 5

                            Hmmh?

                            Same problem as your last thread - the logic of your script isn't really good!!!

                            Why you do not use the structure I showed you there: A script third part unfunction can you fix it?

                             

                            Here is the script I've posted there (extended now with alerts)

                            //---------------------------------------------------------------------------------------- ------------------------------------------------------------------------------- 
                            
                            //var mySelected = Number( app.extractLabel("mDialog") ), 
                              var myDialog = app.dialogs.add({name:"Colse files save \"Yes\" or \"No\"",canCancel:true}); 
                              with(myDialog){ 
                                   with(dialogColumns.add()){ 
                                        with(dialogRows.add()){ 
                                             var mySelection = dropdowns.add({stringList:["01   Yes", "02   No", "03   Reverse"], selectedIndex: 0}); 
                                        } 
                                   } 
                              } 
                            
                            if (myDialog.show() == true) { 
                                var docs = app.documents; 
                                main(); 
                                myDialog.destroy(); 
                                } 
                            
                            function main(){ 
                            if (mySelection.selectedIndex == 0){ 
                                  //colse_file(); 
                                  save_file(); 
                                    // for save function
                                    //alert("saved")
                                  return; 
                                  } 
                            if (mySelection.selectedIndex == 1){ 
                                  close_file(); 
                                    // for close function
                                    //alert("saved")
                                  return; 
                                  } 
                            if (mySelection.selectedIndex == 2){ 
                                  revert_file(); 
                                    // for reverse function
                                    //alert("saved")
                                  return; 
                                  } 
                            } 
                            
                            function save_file(){ // colse_file() 
                                for (var i = docs.length-1; i >= 0; i--) { 
                                    docs[i].close(SaveOptions.YES); 
                                    // for every file
                                    //alert("saved")
                                    
                                    } return; // sorry, the return was on the wrong place before
                            } 
                            
                            function close_file(){ 
                                for (var i = docs.length-1; i >= 0; i--) { 
                                    docs[i].close(SaveOptions.NO); 
                                    // for every file
                                    //alert("closed")
                                    
                                    } return; // sorry, the return was on the wrong place before
                            } 
                            
                            function revert_file(){ 
                                   app.scriptPreferences.userInteractionLevel = UserInteractionLevels.neverInteract; 
                                   app.documents.everyItem().revert(); 
                                   app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll; 
                                   // this is not a loop
                                   //alert("reversed")
                                   return; 
                            } 
                            
                            //---------------------------------------------------------------------------------------- -------------------------------------------------------------------------------
                            
                            

                             

                            Activating the alerts you want should easy fix your problem.

                            Have fun

                             

                            • 11. Re: Why the alert massage return twice on the screen?
                              Teetan VK Level 1

                              Hi,

                               

                              schubser

                               

                              thank you so much

                               

                              VK

                              • 12. Re: Why the alert massage return twice on the screen?
                                pixxxel schubser Level 5

                                You' re welcome.

                                 

                                (Oh, there are two little mistakes in my last posting:

                                line 30 should be "close" and

                                line 36 should be "reversed" in the alert)

                                 

                                Have a nice day

                                 

                                • 13. Re: Why the alert massage return twice on the screen?
                                  Teetan VK Level 1

                                  thanks schubser,

                                   

                                  I got your idea, but not use your script, I know the syntax now, thank you so much.

                                   

                                  but after use the idea, that's conflict to the UndoModes.FAST_ENTIRE_SCRIPT function

                                   

                                  app.doScript('main()', ScriptLanguage.JAVASCRIPT, undefined, UndoModes.FAST_ENTIRE_SCRIPT, "Indent Paragraphs"); 


                                  because I joint 12 scripts together,

                                   

                                  but some script need to undo, but some are not to be undo.

                                   

                                  so that's a lot conflict to the UndoModes.FAST_ENTIRE_SCRIPT function

                                   

                                  can you fix it?

                                   

                                  https://forums.adobe.com/thread/1531927

                                   

                                  VK