4 Replies Latest reply on Mar 26, 2013 2:42 PM by ihba1234

    Extendscript: Couldn't complete the Action, since the destination folder doesn't exist

    ihba1234

      "Adobe Photoshop (CS 6 on mac):Using Extendscript (below) to convert file size from .psd to a .png"

       

       

      Save for web error: Couldn't complete the Action, since the destination folder does not exists". Can anyone help?

       

       

      I am trying to just convert image size from one input folder to an output folder:

       

      #target "photoshop"

       

      var outputWidth = 1024;

      var inputFolder = Folder.selectDialog("Input folder");

      var outputFolder = Folder.selectDialog("Output folder");

       

       

       

       

      if (inputFolder != null && outputFolder != null) {

          var files = inputFolder.getFiles("*.psd");

       

          for (var i = 0; i < files.length; i++) {

       

              var file = files[i];

              var doc = app.open(file);

       

              if (doc.width > outputWidth) {

                  var height = (doc.height / doc.width) * outputWidth;

                  doc.resizeImage(outputWidth + "px", height + "px");

              }

       

              var options = new ExportOptionsSaveForWeb();

              options.format = SaveDocumentType.PNG;

              options.PNG8 = false;

       

       

              doc.exportDocument(outputFolder, ExportType.SAVEFORWEB, options);

          doc.close(SaveOptions.DONOTSAVECHANGES);

              $.writeln('File ' + (i + 1) + ' of ' + files.length + ' processed');

          }

      }

        • 1. Re: Extendscript: Couldn't complete the Action, since the destination folder doesn't exist
          Paul Riggott Level 6

          I have added a few comments, hope this helps...

           

           

          #target "photoshop"
          var outputWidth = 1024;
          var inputFolder = Folder.selectDialog("Input folder");
          var outputFolder = Folder.selectDialog("Output folder");
          var startRulerUnits = preferences.rulerUnits;
          //make sure you are working with pixels
          preferences.rulerUnits = Units.PIXELS;
          if (inputFolder != null && outputFolder != null) {
              var files = inputFolder.getFiles("*.psd");
              for (var i = 0; i < files.length; i++) {
                  var file = files[i];
                  var doc = app.open(file);
                  if (doc.width > outputWidth) {
                      var height = (doc.height / doc.width) * outputWidth;
                     /*  doc.resizeImage(outputWidth + "px", height + "px"); */
                     //only one value is required
                      doc.resizeImage(outputWidth, undefined, undefined, ResampleMethod.BICUBICSHARPER);
                  }
                  var options = new ExportOptionsSaveForWeb();
                  options.format = SaveDocumentType.PNG;
                  options.PNG8 = false;
                  //get the filename without the extension
                  var Name = app.activeDocument.name.replace(/\.[^\.]+$/, '');
                  //build up the output file name and path
                  var saveFile = File(outputFolder + "/" + Name + ".png");
                  //you need to have a full filepath not a folder
                  doc.exportDocument(/*outputFolder */saveFile, ExportType.SAVEFORWEB, options);
              doc.close(SaveOptions.DONOTSAVECHANGES);
                  $.writeln('File ' + (i + 1) + ' of ' + files.length + ' processed');
              }
          //restore ruler units
          app.preferences.rulerUnits = startRulerUnits;
          }
          
          
          • 2. Re: Extendscript: Couldn't complete the Action, since the destination folder doesn't exist
            ihba1234 Level 1

            Hi Paul,

             

            Thanks for the help. It worked.

             

            Can you elaborate the issue that was causing it so that I understand

            • 3. Re: Extendscript: Couldn't complete the Action, since the destination folder doesn't exist
              Paul Riggott Level 6

              You were trying to save the active psd document as outputFolder, but it should have been a complete file object of file path + name + extension type

              If you look at the saveFile var you will see how it is built up.

              Also you need to make sure you are working in pixels else it will use whatever the ruler units are set to.