4 Replies Latest reply on Jul 24, 2014 4:07 PM by Teetan VK

    A script third part unfunction can you fix it?

    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(){

       

          var docs = app.documents;

        

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

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

       

      }

          if (mySelection.selectedIndex == 1){

       

          var docs = app.documents;

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

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

       

      }

       

         if (mySelection.selectedIndex == 2){

       

      var docs = app.documents;

      app.scriptPreferences.userInteractionLevel = UserInteractionLevels.neverInteract;

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

      app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;

       

      }

      }

      }

      //---------------------------------------------------------------------------------------- -------------------------------------------------------------------------------

       

       

      3rd part: revert

      unfunction

       

      can you fix it?

       

      VK

        • 1. Re: A script third part unfunction can you fix it?
          pixxxel schubser Level 5

          Hmmh?

          What do you really want?

           

          Please try something like this:

          var aDoc = app.activeDocument;
          if (aDoc.saved) {
          app.scriptPreferences.userInteractionLevel = UserInteractionLevels.neverInteract;
          aDoc.revert();
          app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
          } else { alert ("unsaved document");}
          

           

          This reverts the document to its state at the last save operation.

           

          Have fun

           

          • 2. Re: A script third part unfunction can you fix it?
            Jump_Over Level 5

            Hi,

             

            Fixing a provided code - since if (mySelection.selectedIndex == 0) condition is missed ==>all doc are saved regardless of user choice. So reverting may look like saving after OP's code does a job...

            ...may look but does not work since all doc are closed as well.

             

            Jarek

            • 3. Re: Re: A script third part unfunction can you fix it?
              pixxxel schubser Level 5

              @Jump_Over,

              that's right.

               

              But the logic of this script isn't really good.

              IMHO this (only quick and dirty, and not tested saving and closing) should be a little bit better:

              //---------------------------------------------------------------------------------------- -------------------------------------------------------------------------------
              
              //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();
                    return;
                    }
              if (mySelection.selectedIndex == 1){
                    close_file();
                    return;
                    }
              if (mySelection.selectedIndex == 2){
                    revert_file();
                    return;
                    }
              }
              
              function save_file(){ // colse_file()
                  for (var i = docs.length-1; i >= 0; i--) {
                      docs[i].close(SaveOptions.YES);
                      //return;
                      } return; //edited, the return was on a wrong place before
              }
              
              function close_file(){
                  for (var i = docs.length-1; i >= 0; i--) {
                      docs[i].close(SaveOptions.NO);
                      //return;
                      } return; //edited, the return was on a wrong place before
              }
              
              function revert_file(){
                     app.scriptPreferences.userInteractionLevel = UserInteractionLevels.neverInteract;
                     app.documents.everyItem().revert();
                     app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
                     return;
              }
              
              //---------------------------------------------------------------------------------------- -------------------------------------------------------------------------------
              
              
              • 4. Re: A script third part unfunction can you fix it?
                Teetan VK Level 1

                thanks all guys

                 

                thank you so much

                 

                 

                VK