3 Replies Latest reply on Jun 5, 2014 8:35 AM by C_Barnes

    Help! Fix my javascript to save a bmp with suffix in the same folder as the previous save.

    C_Barnes

      Here's my current javascript:

       

       

      #target photoshop

       

       

      // sets document preferences to inches

      app.preferences.rulerUnits = Units.INCHES

       

       

      // these are our values for the END RESULT width and height (in inches) of our image

      var fWidth = 11.73;

      var fHeight = 5.97;

       

       

      var CurrentDLPFile=app.activeDocument

      var CurrentDLPFileName= CurrentDLPFile.name

      var CurrentDLPFilePath="~/Desktop/fetch"

      var f = File.saveDialog('Save Where?',''); 

       

       

      // in case we double clicked the file

      app.bringToFront();

       

       

      // resizes the canvas to 11.73 x 5.97 inches

      CurrentDLPFile.resizeCanvas(UnitValue(fWidth,"in"),UnitValue(fHeight,"in"));

       

       

      // flattens all layers

      CurrentDLPFile.flatten();

       

       

      // saves as photoshop file

      if (f!=null) CurrentDLPFile.saveAs(f,undefined);

       

       

      // splits channels

      CurrentDLPFile.splitChannels();

       

       

      // converts active K seperation to bitmap form

      var bitsaveoptions = new BitmapConversionOptions()

       

       

      bitsaveoptions.method = BitmapConversionType.HALFTONESCREEN

      bitsaveoptions.angle = 45

      bitsaveoptions.frequency = 55

      bitsaveoptions.resolution = 300

      bitsaveoptions.shape = BitmapHalfToneType.ROUND

       

       

      app.activeDocument.changeMode(ChangeMode.BITMAP,bitsaveoptions);

       

      // THIS IS WHERE I'M HAVING ISSUES- I want to save the file (which at this point is a bmp), with a suffix of 1 in the same folder; and then close the file.

      var doc = app.activeDocument;

      var docName = doc.name;

      docName = docName.match(/(.*)(\.[^\.]+)/) ? docName = docName.match(/(.*)(\.[^\.]+)/):docName = [docName, docName];

      var suffix = '_1';

      var saveName = new File(decodeURI(doc.path)+'/'+docName[1]+suffix+'.bmp');

       

      function saveFile(app.activeDocument, saveName);

        • 1. Re: Help! Fix my javascript to save a bmp with suffix in the same folder as the previous save.
          pixxxel schubser MVP & Adobe Community Professional

          Hi c_barnes,

          Try this to get the saveName with path for your saveFile:

          var doc = app.activeDocument;
          var saveFile = File(File(doc.path)+"/"+doc.name.replace (/\.bmp$/,'_1.bmp'));
          alert(saveFile);
          
          

           

          Is this ok for you?

           

          • 2. Re: Help! Fix my javascript to save a bmp with suffix in the same folder as the previous save.
            C_Barnes Level 1

            Hi pixxel,

             

            ExtendScript still won't run my code:

             

            // saves K seperation to bitmap form

            saveBMP = new BMPSaveOptions();

            saveBMP.alphaChannels = false;

            saveBMP.depth = BMPDepthType.ONE;

            saveBMP.flipRowOrder = false;

            saveBMP.rleCompression = false;

            saveBMP.osType = OperatingSystem.WINDOWS;

             

             

            var doc = activeDocument;

            var saveFile = File(File(doc.path)+"/"+doc.name.replace (/\.bmp$/,'_1.bmp'));

            activeDocument.saveAs(saveFile, saveBMP, true, Extension.LOWERCASE); 

            activeDocument.close( SaveOptions.DONOTSAVECHANGES );

            activeDocument.close()

             

            ^the bolded line above is where it runs into issues... any ideas? Thanks for your help!

            • 3. Re: Help! Fix my javascript to save a bmp with suffix in the same folder as the previous save.
              C_Barnes Level 1

              I figured it out, here's for anyone else who is struggling with a similar problem:

               

              var CurrentDLPFile=app.activeDocument

               

              // saves active doc as photoshop file

              if (f!=null) CurrentDLPFile.saveAs(f,undefined);

               

              //renames active document to whatever was saved

              var CurrentDLPFile = app.activeDocument.name

               

              //assigns the location of the saved psd

              var psdPath = activeDocument.path

              saveBMP = new BMPSaveOptions();

              saveBMP.alphaChannels = false;

              saveBMP.depth = BMPDepthType.ONE;

              saveBMP.flipRowOrder = false;

              saveBMP.rleCompression = false;

              saveBMP.osType = OperatingSystem.WINDOWS;

               

              var doc = app.activeDocument; 

              var Name = doc.name.replace(/\.[^\.]+$/, '');  

              var Suffix = "1"; 

               

              var saveFile = File(psdPath + "/" + Name + Suffix + ".bmp");

              activeDocument.saveAs(saveFile, saveBMP, true, Extension.LOWERCASE); 

              activeDocument.close( SaveOptions.DONOTSAVECHANGES );