8 Replies Latest reply on Oct 11, 2015 10:11 PM by Upendra_sengar

    Can we know whether Cancel is clicked or Save is clicked?

    Upendra_sengar Level 2

      Hi,

       

      i'm using command app.executeMenuCommand("saveAs") to open saveAs dialog. if i click save button then i need to follow some steps but if cancel clicked then need to do something else so i'm unable to get which button is clicked. is there any way to move out of this issue.

       

      Note: I don't want to save as the document with app.document[0].saveAs() method because this will not show save as options dialog.

       

       

      please help is possible.

       

       

      Thanks,

      Upendra sengar.

        • 1. Re: Can we know whether Cancel is clicked or Save is clicked?
          CarlosCanto Adobe Community Professional & MVP

          use, selectDialog() or saveDialog() before saving using app.document[0].saveAs()

           

          check the Tools Guide or search the forums for details.

          • 2. Re: Can we know whether Cancel is clicked or Save is clicked?
            Silly-V Adobe Community Professional

            You could try if(app.documents[0].saved){} to see if the document has been saved.

            Since it won't work if the document you're saving already had no changes, you can force a change such as adding & removing some path item, or comparing before & after document names.

            • 3. Re: Can we know whether Cancel is clicked or Save is clicked?
              Qwertyfly... Level 4

              on Silly-V's train of thought.

              you could use:

              ModTime = MyFile.modified;

              and compare that to current time

              • 4. Re: Can we know whether Cancel is clicked or Save is clicked?
                CarlosCanto Adobe Community Professional & MVP

                Right, but I think the OP is not trying to just save, I think he wants to bring up the dialog to pick a folder and opt to exit out if possible.

                • 5. Re: Can we know whether Cancel is clicked or Save is clicked?
                  Qwertyfly... Level 4

                  right you are,

                  It would be good to get a look at Upendra's code.

                  My first thought is that your correct in saying he is just after the folder.

                   

                  I also understand the desire to use the saveAs dialog over the selectDialog.

                  The saveAs dialog looks a lot better.

                   

                  again, seeing the code would give us a better understanding of what the script is aiming to achieve

                  • 6. Re: Can we know whether Cancel is clicked or Save is clicked?
                    Silly-V Adobe Community Professional

                    The native Save dialog is probably what he's after, since it lists all the file types and related options, but that's just my take on it

                    • 7. Re: Can we know whether Cancel is clicked or Save is clicked?
                      Upendra_sengar Level 2

                              if (app.documents[0].path != "" && app.documents[0].saved) {

                                  global_templateFilePath = app.documents[0].fullName;

                                  for (var index = 0; index < layerSetArray.length; index++) {

                                      var layersNameArray = layerSetArray[index].layerNames.split(',');

                                      var layerSetName = layerSetArray[index].layerSetName

                                      app.executeMenuCommand("saveas");

                                      var saveAsFileName = app.documents[0].name;

                                      var saveAsFilePath = app.documents[0].path;

                                      if (String(global_templateFilePath) != String(app.documents[0].fullName)) {

                                          var newDoc = app.documents[0];

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

                                              if (layersNameArray.indexOf(newDoc.layers[i].name) == -1) {

                                                  newDoc.layers[i].visible = true;

                                                  newDoc.layers[i].remove();

                                              } else

                                                  newDoc.layers[i].visible = true;

                                          }

                                          deleteLayerSetEntryFromXMP();

                                          newDoc.save();

                                          var fileName = newDoc.name;

                                          var filePath = newDoc.path;

                                          var folder = new Folder(filePath + "/" + layerSetName + "_Folder");

                                          if (!folder.exists)

                                              folder.create();

                                          var filePath = folder;

                                          var finalFileName = new File(filePath + "/" + fileName);

                                          app.documents[0].saveAs(finalFileName);

                                          var removeFileObject = new File(saveAsFilePath + "/" + saveAsFileName);

                                          removeFileObject.remove();

                                          app.documents[0].close();

                                      } else

                                          alert("Document must be saved at different location or with different name !!! \n\t\t\t OR \n\t\t     User clicked Cancel !!! ");

                                  }

                              } else

                                  alert("Document must be saved!!!")