9 Replies Latest reply on Sep 18, 2016 4:30 PM by Vfxvenkat98

    save files in a done folder

    Vfxvenkat98 Level 1

      hi,

      i need to save the new .jpg images in same location of the active document in a seperate folder called Done folder.

      Right now this script saved the jpegs  in same location without a folder

      Kindly help me on this script

       

      #target photoshop;  

      if (app.documents.length > 0) {  

          var thedoc = app.activeDocument;  

          // getting the name and location;  

          var docName = thedoc.name;  

          if (docName.indexOf(".") != -1) { 

              var basename = docName.match(/(.*)\.[^\.]+$/)[1]; 

          } else { 

              var basename = docName; 

          };  

          // getting the location, if unsaved save to desktop;  

          try { 

              var docPath = thedoc.path}  

          catch (e) { 

              var docPath = "~/Desktop" 

          };  

          // 

          var layerSets_ = app.activeDocument.layerSets; 

          for (var a =0; a < layerSets_.length; a++) { 

              // turn all layerSets invisible 

              for (var b =0; b < layerSets_.length; b++) { 

                  layerSets_[b].visible = false; 

              } 

              layerSets_[a].visible = true; 

              // jpg options;  

              var jpegOptions = new JPEGSaveOptions();  

              jpegOptions.quality = 12;  

              jpegOptions.embedColorProfile = true;  

              jpegOptions.matte = MatteType.NONE;  

              //save jpg in layerset name:  

              thedoc.saveAs(new File(docPath+'/'+layerSets_[a].name+'.jpg'),jpegOptions,true);

              //thanks to xbytor; 

          } 

      };

        • 1. Re: save files in a done folder
          Pedro Cortez Marques Level 3

          Hi!

           

          Just change this:

          thedoc.saveAs(new File(docPath+'/'+layerSets_[a].name+'.jpg'),jpegOptions,true);
          

           

          with this:

           

          var outFolder = Folder(docPath+'/Done');
          if (!outFolder.exists) outFolder.create();
          thedoc.saveAs(new File(outFolder +'/'+layerSets_[a].name+'.jpg'),jpegOptions,true);
          

           

          With folders, you have to creat them before using them to put files. If you don't, the file will not be saved.

          Hope it helps.

          • 2. Re: save files in a done folder
            Vfxvenkat98 Level 1

            Thanks Marques

             

            but i also want that files in .tif format also in TIFF

             

            how to replace the .jpg options to .tiff options ??

            • 3. Re: save files in a done folder
              Vfxvenkat98 Level 1

              So that save my layersets into TIFF files into TIFF FOLDER

              • 4. Re: save files in a done folder
                Pedro Cortez Marques Level 3

                Hi, you have that answered on other posts on this forum.

                 

                But I send you one of possibilities:

                 

                #target photoshop;  
                if (app.documents.length > 0) {  
                    var thedoc = app.activeDocument;  
                    // getting the name and location;  
                    var docName = thedoc.name;  
                    if (docName.indexOf(".") != -1) { 
                        var basename = docName.match(/(.*)\.[^\.]+$/)[1]; 
                    } else { 
                        var basename = docName; 
                    };  
                    // getting the location, if unsaved save to desktop;  
                    try { 
                        var docPath = thedoc.path}  
                    catch (e) { 
                        var docPath = "~/Desktop" 
                    };  
                    // 
                    var layerSets_ = app.activeDocument.layerSets; 
                    for (var a =0; a < layerSets_.length; a++) { 
                        // turn all layerSets invisible 
                        for (var b =0; b < layerSets_.length; b++) { 
                            layerSets_[b].visible = false; 
                        } 
                        layerSets_[a].visible = true; 
                        // TIFF  
                        SaveTiff(File(docPath+'/'+layerSets_[a].name+'.TIFF'));
                    } 
                };
                
                
                function SaveTiff(saveFile) {
                    tiffSaveOptions = new TiffSaveOptions();
                    tiffSaveOptions.alphaChannels = false;  
                    tiffSaveOptions.annotations = false;  
                    tiffSaveOptions.byteOrder = ByteOrder.IBM;  
                    tiffSaveOptions.embedColorProfile = true;  
                    tiffSaveOptions.imageCompression = TIFFEncoding.NONE;  
                    tiffSaveOptions.layerCompression = LayerCompression.RLE;  
                    tiffSaveOptions.layers = true;  
                    tiffSaveOptions.saveImagePyramid = false;  
                    tiffSaveOptions.spotColors = false;  
                    tiffSaveOptions.transparency = true;  
                    activeDocument.saveAs(saveFile, tiffSaveOptions, true, Extension.LOWERCASE);  
                }
                
                
                
                
                • 5. Re: save files in a done folder
                  Vfxvenkat98 Level 1

                  but this script saves all the layersets in everydocument document but i need only one layerset in one document

                  • 6. Re: save files in a done folder
                    Vfxvenkat98 Level 1

                    it should take only one layergroup from the main document and save it along with background  layer

                    • 7. Re: save files in a done folder
                      Pedro Cortez Marques Level 3

                      Do you mind to explain what you want all at once, please?

                       

                      I cant't guess what layer group you want to save. Do you want the script to as you if there are more than one?

                      • 8. Re: save files in a done folder
                        Vfxvenkat98 Level 1

                        Right now the script will export each layer group into jpeg .so it will process what are all layer groups available  in the main document.

                         

                        now the same i need those files in .TIFF format in a separate folder Done 2

                         

                        i want each layer-group in the main document to be saved as a different files in done folder along with background layer and that layer group of main document.

                         

                        For example

                        i opened my Master.tiff document in Photoshop.

                        It is having multiple layer sets like 1,2,3,4,5.

                        Now i want to export all these five layer sets into 5 .tiff files along with same background.

                        • 9. Re: save files in a done folder
                          Vfxvenkat98 Level 1

                          #target photoshop 

                          function main(){ 

                          if(!documents.length) return; 

                          var doc = activeDocument; 

                          var oldPath = activeDocument.path; 

                          for(var a=0;a<doc.layerSets.length;a++){ 

                          activeDocument.activeLayer = activeDocument.layers.getByName(doc.layerSets[a].name); 

                          dupLayers(); 

                          // activeDocument.mergeVisibleLayers();// Merge visible layer 

                          activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true); 

                          var saveFile= File(oldPath +"/"+doc.layerSets[a].name +".psd"); 

                          SavePSD(saveFile); 

                          app.activeDocument.close(SaveOptions.DONOTSAVECHANGES); 

                              } 

                          main(); 

                          function dupLayers() {  

                              var desc143 = new ActionDescriptor(); 

                                  var ref73 = new ActionReference(); 

                                  ref73.putClass( charIDToTypeID('Dcmn') ); 

                              desc143.putReference( charIDToTypeID('null'), ref73 ); 

                              desc143.putString( charIDToTypeID('Nm  '), activeDocument.activeLayer.name ); 

                                  var ref74 = new ActionReference(); 

                                  ref74.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') ); 

                              desc143.putReference( charIDToTypeID('Usng'), ref74 ); 

                              executeAction( charIDToTypeID('Mk  '), desc143, DialogModes.NO ); 

                          }; 

                          function SavePSD(saveFile){  

                          psdSaveOptions = new PhotoshopSaveOptions();  

                          psdSaveOptions.embedColorProfile = true;  

                          psdSaveOptions.alphaChannels = true;   

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

                           

                           

                           

                           

                          In the above script it duplicates every layer and save it as  psd without background layer but i want it saved as TIFF along with same backgroud  for all documents in a seperate done folder

                           

                          anyone help me on this to complete this cript