2 Replies Latest reply: May 4, 2009 9:04 PM by Robdogg RSS

    Total noob, need help

    Robdogg

      I've never scripted Photoshop ever, but I am c# guy during the day, so I know programming

       

      Ok, here is what I do right now: I place 3 photos into my scanner, scan them into Photoshop CS4 using the File/Import/Scanner menu item.  Then I go to File/Automate/Crop and Straighten Photos to split up the image into 3 photos.  Photoshop creates a tab for each photo.  Then I go to each individual tab and save each picture.  Then start again with the scanning - rinse and repeat.

       

      This is kind of tedious.  I am looking to automate all or some portion of this task.  For instance, I would love it, if there was a script that responded to the Image Imported from Scanner event (if such a thing even exists), split the photos into 3 using the Crop and Straighten Photos command and saved each photo as a PNG (without getting the stupid dialog box asking me whether I was it interlaced or not).  The routine that saves the photos, would have to look in the directory and name the file in a numeric fashion (e.g. p1.png, p2.png, p3.png, etc...) and not overwrite photos.

       

      Is such a thing possible?  If so, what are some of the resources I should look at?  Is there something simpler (like maybe a macro recorder), that I am not looking at? 

       

      Thanks.

        • 1. Re: Total noob, need help
          Paul Riggott Community Member

          One way of doing it would be to do all the scans and place the files in their own folder (jpg/tif/pdf)

          Then you can run the following script that will create a new folder off the existing one and batch split all the files naming them existingFileName#001.png and put them in the new folder (edited)

           

          #target Photoshop
          app.bringToFront;
          var inFolder = Folder.selectDialog("Please select folder to process");
          if(inFolder != null){
          var fileList = inFolder.getFiles(/\.(jpg|tif|psd|)$/i);
          var outfolder = new Folder(decodeURI(inFolder) + "/Edited");
          if (outfolder.exists == false) outfolder.create();
          for(var a = 0 ;a < fileList.length; a++){
          if(fileList[a] instanceof File){
          var doc= open(fileList[a]);
          doc.flatten();
          var docname = fileList[a].name.slice(0,-4);
          CropStraighten();
          doc.close(SaveOptions.DONOTSAVECHANGES);
          var count = 1;
          while(app.documents.length){
          var saveFile = new File(decodeURI(outfolder) + "/" + docname +"#"+ zeroPad(count,3) + ".png");
          SavePNG(saveFile);
          activeDocument.close(SaveOptions.DONOTSAVECHANGES) ;
          count++;
            }
          }
          }
          };
          function CropStraighten() {
          function cTID(s) { return app.charIDToTypeID(s); };
          function sTID(s) { return app.stringIDToTypeID(s); };
          executeAction( sTID('CropPhotosAuto0001'), undefined, DialogModes.NO );
          };
          function SavePNG(saveFile){
              pngSaveOptions = new PNGSaveOptions();
              pngSaveOptions.embedColorProfile = true;
              pngSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
              pngSaveOptions.matte = MatteType.NONE;
              pngSaveOptions.quality = 1;
          pngSaveOptions.PNG8 = false; //24 bit PNG
              pngSaveOptions.transparency = true;
          activeDocument.saveAs(saveFile, pngSaveOptions, true, Extension.LOWERCASE);
          }
          function zeroPad(n, s) {
          n = n.toString();
          while (n.length < s) n = '0' + n;
          return n;
          };

          • 2. Re: Total noob, need help
            Robdogg Community Member

            Dude, you are so the MAN.  This is exactly what I needed!!!  Many thanks.

             

            The only change I made is in the following line:

            var fileList = inFolder.getFiles(/\.(jpg|tif|png|)$/i);

             

            I changed psd to png, since I don't care about psd files in this instance.

             

            Now if someone can come up with a robot that can take photos out of the album and place them onto the scanner, that would be so sweet.

             

            Regards