3 Replies Latest reply on Mar 18, 2013 3:23 PM by Mark Ashton

    Save For Web script

    MsKimski

      Hi!

      I'm trying just to create an action which would Save opened file For Web with the same name in the same directory.

      While recording the action I choose all parameters needed and replace an existing original file with the new one. Nothing special.

      On my Mac it works perfectly well - saves and replaces. But while being run on Windows it continues asking whether I'd like to replace the existing file.

      Any ideas what I should change for Windows?

       

      here is a part of my script:

       

      var idExpr = charIDToTypeID( "Expr" );

          var desc2 = new ActionDescriptor();

          var idUsng = charIDToTypeID( "Usng" );

              var desc3 = new ActionDescriptor();

              var idOp = charIDToTypeID( "Op  " );

              var idSWOp = charIDToTypeID( "SWOp" );

              var idOpSa = charIDToTypeID( "OpSa" );

              desc3.putEnumerated( idOp, idSWOp, idOpSa );

              var idDIDr = charIDToTypeID( "DIDr" );

              desc3.putBoolean( idDIDr, true );

              var idIn = charIDToTypeID( "In  " );

              var fileName = app.activeDocument.name;

              var filePath = app.activeDocument.path;

              desc3.putPath( idIn, new File( filePath) );

              var idFmt = charIDToTypeID( "Fmt " );

              var idIRFm = charIDToTypeID( "IRFm" );

              var idJPEG = charIDToTypeID( "JPEG" );

              desc3.putEnumerated( idFmt, idIRFm, idJPEG );

              ..............

              var idovSN = charIDToTypeID( "ovSN" );

              desc3.putString( idovSN, "images" );

          var idSaveForWeb = stringIDToTypeID( "SaveForWeb" );

          desc2.putObject( idUsng, idSaveForWeb, desc3 );

      executeAction( idExpr, desc2, DialogModes.NO );

        • 1. Re: Save For Web script
          Michael L Hale Level 5

          I would have thought it would ask about replacing the existing file on either platform. However a simple fix would be to remove the file before runnig the export.

          1 person found this helpful
          • 2. Re: Save For Web script
            MsKimski Level 1

            Thank you! It works with removal

            (but in fact, I really don't have to delete a file on Mac, script replaces it without asking)

            • 3. Re: Save For Web script
              Mark Ashton

              I think it would probably be easier to do it this way. I use this code across windows and mac and it works great and never asks to replace;

              var Qlt = 50 //// whatever quality you want to save it as.

              var FileNm =  new File ((activeDocument.path) + "/" + (activeDocument.name)); ///// the path to your file

               

               

              ExpWeb(FileNm, Qlt); //// performs export for web

               

               

              ///////// Export for web function

               

               

              function ExpWeb(FileNm, Qlt)

              {

                    var options = new ExportOptionsSaveForWeb();

                    options.quality = Qlt;   // Start with highest quality (biggest file).

                    options.format = SaveDocumentType.JPEG;   // Save Format for the file

                    activeDocument.exportDocument(new File(FileNm), ExportType.SAVEFORWEB, options);

               

              }