1 Reply Latest reply on Oct 3, 2011 5:21 AM by c.pfaffenbichler

    auto no in file name

    johan sacheng

      dear ALL,

       

      when save for web,

       

      how to include the script to add auto number such as

       

      file2email > file2email_001  (002, 003 etc)

       

      in photoshop action script..

       

      thx!

        • 1. Re: auto no in file name
          c.pfaffenbichler Level 9

          Could you give this a try (paste the following text into a new file in ExtendScript Toolkit (part of Photoshop’s installation, Applications/Utilities/Adobe Utilities/ExtendScript Toolkit CS4 or /Applications/Utilities/Adobe Utilities-CS5/ExtendScript Toolkit CS5) and save it as a jsx-file into Photoshop’s Presets/Scripts-folder):

          // this script saves a png with progressive number added;
          // 2011, use it at your own risk;
          #target photoshop;
          if (app.documents.length > 0) {
                    var myDocument = app.activeDocument;
          // getting the name and location;
                    var docName = myDocument.name;
          // thanks to xbytor;
                    var baseName = docName.match(/(.*)\.[^\.]+$/)[1];
          //getting the location;
                    var docPath = myDocument.path;
          // duplicate the image;
          // weboptions;
                    var webOptions = new ExportOptionsSaveForWeb();
                    webOptions.format = SaveDocumentType.PNG;
                    webOptions.PNG8 = false; 
                    webOptions.transparency = true;
                    webOptions.interlaced = 0;
                    webOptions.includeProfile = false;
                    webOptions.optimized = true;
          // determine the number;
                    var thePlaces = 1;
                    var theNumber = bufferNumberWithZeros(1, 3)
                    while (File(docPath+"/"+baseName+"_"+theNumber+".png").exists == true) {
                              theNumber = bufferNumberWithZeros(Number(theNumber) + 1, 3);
                              };
          //save jpg;
                    myDocument.exportDocument((new File(docPath+"/"+baseName+"_"+theNumber+".png")), ExportType.SAVEFORWEB,webOptions);
                    };
          ////// buffer number with zeros //////
          function bufferNumberWithZeros (number, places) {
                    var theNumberString = String(number);
                    for (var o = 0; o < (places - String(number).length); o++) {
                              theNumberString = String("0" + theNumberString)
                              };
                    return theNumberString
                    };
          
          1 person found this helpful