11 Replies Latest reply on Apr 2, 2016 10:15 AM by phoenix830

    Script to save as tif with zip compression, file name from properties

    phoenix830

      I don't know anything about scripting so I am unable to understand the answers to similar questions and merge an answer for mine.

       

      I am looking for a script to save my scanned images as tiff with zip compression using the Document Title from the file properties.

      I want to assign it to a button to save me time, Scanning images takes enough time as it is

       

      Thank you in advance for any help.

        • 1. Re: Script to save as tif with zip compression, file name from properties
          SuperMerlin Level 5

          Try this.

          #target photoshop;
          
          main();
          function main(){
          try{
          var Path = activeDocument.path;
          }catch(e){
              alert("This document needs to have been saved before running this script!");
              return;
              }
          var fileName =activeDocument.info.title;
          if(fileName == '') {
              alert("There is no title in this document");
              return;
              }
          var saveFile = File(Path + "/" + fileName + ".tif");
          app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
          };
          function SaveTIFF(saveFile){
          tiffSaveOptions = new TiffSaveOptions(); 
          tiffSaveOptions.embedColorProfile = true; 
          tiffSaveOptions.alphaChannels = true; 
          tiffSaveOptions.layers = true;
          tiffSaveOptions.imageCompression = TIFFEncoding.TIFFZIP; 
          activeDocument.saveAs(saveFile, tiffSaveOptions, true, Extension.LOWERCASE); 
          };
          
          
          
          • 2. Re: Script to save as tif with zip compression, file name from properties
            phoenix830 Level 1

            Thank you for the quick reply.


            I have tried the script but I need to save it before running the script. I was hoping to use the script as a Save as is that possible?

            • 3. Re: Script to save as tif with zip compression, file name from properties
              SuperMerlin Level 5

              This will prompt you for the output folder.

              #target photoshop;
              
              main();
              function main(){
              var Path = Folder.selectDialog( "Please select output folder");
              if(Path == null){
                  alert("You need to select an output folder!");
                  return;
                  }
              var fileName =activeDocument.info.title;
              if(fileName == '') {
                  alert("There is no title in this document");
                  return;
                  }
              var saveFile = File(Path + "/" + fileName + ".tif");
              app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
              };
              function SaveTIFF(saveFile){
              tiffSaveOptions = new TiffSaveOptions(); 
              tiffSaveOptions.embedColorProfile = true; 
              tiffSaveOptions.alphaChannels = true; 
              tiffSaveOptions.layers = true;
              tiffSaveOptions.imageCompression = TIFFEncoding.TIFFZIP; 
              activeDocument.saveAs(saveFile, tiffSaveOptions, true, Extension.LOWERCASE); 
              };
              
              
              
              1 person found this helpful
              • 4. Re: Script to save as tif with zip compression, file name from properties
                phoenix830 Level 1

                Thank you again. I am able to select to location but it doesn't save.

                I removed  app.activeDocument.close(SaveOptions.DONOTSAVECHANGES); because it just closed without saving. The location I am saving id D:\Scanned Images

                 

                After figuring some of it out I got this from a different thread and the answer you supplied

                 

                1. var fileName =activeDocument.info.title;
                2. var saveFile = new File("d:/" + fileName + ".tif");
                3. tiffSaveOptions = new TiffSaveOptions();
                4. tiffSaveOptions.embedColorProfile = true;
                5. tiffSaveOptions.alphaChannels = true;
                6. tiffSaveOptions.layers = true;
                7. tiffSaveOptions.imageCompression = TIFFEncoding.TIFFZIP;
                8. activeDocument.saveAs(saveFile, TiffSaveOptions, true, Extension.LOWERCASE);

                 

                This creates the file as I wanted, The problem is I can not get a if else command to work like the one from your code  "

                if(fileName == '') { 

                    alert("There is no title in this document"); 

                    return; 

                    } 

                "

                Was I right saving it as a .jsx I first saved it as .vbr but while trying to learn what I was reading I figured it was Javascript

                • 5. Re: Script to save as tif with zip compression, file name from properties
                  phoenix830 Level 1

                  On an other subject do you use Adobe Configurator?

                  I am using VueScan and want to speed up my scanning by using Adobe Configurator to create a easy access button. However the option isnt there. I was wondering if you knew what the script would be?  Below is the code for inserting a note. I think I need to edit the 'importAnnots' but not sure what to



                  ErrStrs = {}; ErrStrs.USER_CANCELLED=localize("$$$/ScriptingSupport/Error/UserCancelled=User cancelled the operation"); try {var idimportAnnots = stringIDToTypeID( 'importAnnots' );     var desc1085 = new ActionDescriptor(); executeAction( idimportAnnots, desc1085, DialogModes.ALL ); } catch(e){if (e.toString().indexOf(ErrStrs.USER_CANCELLED)!=-1) {;} else{alert(localize("$$$/ScriptingSupport/Error/CommandNotAvailable=The command is currently not available"));}}

                  • 6. Re: Script to save as tif with zip compression, file name from properties
                    phoenix830 Level 1

                    Sorry one more thing how would it deal with duplicates? I would like it to add a number on the end instead of overwriting

                    • 7. Re: Script to save as tif with zip compression, file name from properties
                      SuperMerlin Level 5

                      This should now as I have tested this version.

                      There is no prompt it just saves to the scanned folder.

                      Yes it should be a jsx file.

                      #target photoshop;
                      
                      main();
                      function main(){
                      var Path = Folder("/D/Scanned");
                      if(!Path.exists){
                          alert(Path + " does not exist!");
                          return;
                          }
                      var fileName =activeDocument.info.title;
                      if(fileName == '') {
                          alert("There is no title in this document");
                          return;
                          }
                      var saveFile = File(Path + "/" + fileName + ".tif");
                      SaveTIFF(saveFile);
                      app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
                      };
                      function SaveTIFF(saveFile){
                      tiffSaveOptions = new TiffSaveOptions(); 
                      tiffSaveOptions.embedColorProfile = true; 
                      tiffSaveOptions.alphaChannels = true; 
                      tiffSaveOptions.layers = true;
                      tiffSaveOptions.imageCompression = TIFFEncoding.TIFFZIP; 
                      activeDocument.saveAs(saveFile, tiffSaveOptions, true, Extension.LOWERCASE); 
                      };
                      
                      
                      
                      • 8. Re: Script to save as tif with zip compression, file name from properties
                        phoenix830 Level 1

                        This overrides files with the same name is it possible to prevent this?

                        • 9. Re: Script to save as tif with zip compression, file name from properties
                          SuperMerlin Level 5

                          If the file exists this will append the time so it will be a different file name.

                           

                          
                          

                          #target photoshop;

                           

                          main();

                          function main(){

                          var Path = Folder("/D/Scanned");

                          if(!Path.exists){

                              alert(Path + " does not exist!");

                              return;

                              }

                          var fileName =activeDocument.info.title;

                          if(fileName == '') {

                              alert("There is no title in this document");

                              return;

                              }

                          var saveFile = File(Path + "/" + fileName + ".tif");

                          if(saveFile.exists) saveFile = File(Path + "/" + fileName +"-" + time() + ".tif");

                          SaveTIFF(saveFile);

                          app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

                          };

                          function SaveTIFF(saveFile){

                          tiffSaveOptions = new TiffSaveOptions();

                          tiffSaveOptions.embedColorProfile = true;

                          tiffSaveOptions.alphaChannels = true;

                          tiffSaveOptions.layers = true;

                          tiffSaveOptions.imageCompression = TIFFEncoding.TIFFZIP;

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

                          };

                          function time(){

                          var date = new Date();

                              var d  = date.getDate();

                              var day = (d < 10) ? '0' + d : d;

                              var m = date.getMonth() + 1;

                              var month = (m < 10) ? '0' + m : m;

                              var yy = date.getYear();

                              var year = (yy < 1000) ? yy + 1900 : yy;

                              var digital = new Date();

                              var hours = digital.getHours();

                              var minutes = digital.getMinutes();

                              var seconds = digital.getSeconds();

                              var amOrPm = "AM";

                              if (hours > 11) amOrPm = "PM";

                              if (hours > 12) hours = hours - 12;

                              if (hours == 0) hours = 12;

                              if (minutes <= 9) minutes = "0" + minutes;

                              if (seconds <= 9) seconds = "0" + seconds;

                              todaysDate =  hours + "-" + minutes + "-" + seconds + amOrPm;

                              return todaysDate.toString();

                          };

                          • 10. Re: Script to save as tif with zip compression, file name from properties
                            phoenix830 Level 1

                            Goin to add a time stamp to the end of it when I look at it tomorrow changing the code adds numbers to the end will google time stamp then

                             

                             

                             

                            var thistimestamp = Math.round(new Date().getTime() / 1000);

                              var saveFile = File(Path + "/" + fileName + "--" + thistimestamp +".tif"); 

                            SaveTIFF(saveFile); 

                             

                             

                            Thank you for the time you have spent helping me