33 Replies Latest reply on Jul 9, 2015 3:59 AM by mariap14286444

    Applying files in PS in bulk

    mariap14286444 Level 1

      I use the script below which turns every group into a JPEG. It works perfectly. I select a PNG design to go into a smart layer in Photoshop which then sits on an image of a product.

       

      My question is, I have 3000 designs. Is there a way to make a large selection of PNG files that I want importing into Photoshop, to put into the smart layer I have arranged, close and save the smart layer so it is then applied to each product, and then using this script to save each group as a JPEG?

       

      Many thanks for any help!

       

      #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(); 
              activeDocument.trim

       

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

              var saveFile= File(oldPath +"/NAMEHERE

       

      -"+doc.layerSets[a].name +".jpg"); 

              saveJPG(saveFile,10); 
              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 saveJPG(saveFile, jpegQuality) { 
          app.activeDocument.flatten();  
          jpgSaveOptions = new JPEGSaveOptions(); 
          jpgSaveOptions.embedColorProfile = true; 
          jpgSaveOptions.formatOptions =

       

      FormatOptions.STANDARDBASELINE; 

          jpgSaveOptions.matte = MatteType.NONE; 
          jpgSaveOptions.quality = jpegQuality; //1-12 
          activeDocument.saveAs(saveFile, jpgSaveOptions,

       

      true,Extension.LOWERCASE); 

        • 1. Re: Applying files in PS in bulk
          Chuck Uebele Adobe Community Professional & MVP

          If I'm understanding correctly, you can assign your script to an action then run the action using the batch script in Bridge or PS. You can also script something that gets all the files from a folder and loops through them to apply your script.

          1 person found this helpful
          • 2. Re: Applying files in PS in bulk
            mariap14286444 Level 1

            Chuck Uebele wrote:

             

            You can also script something that gets all the files from a folder and loops through them to apply your script.

             

            That's great. How would I go about writing a script that gets all files from a folder and puts them into a smart layer and runs my default script in the previous post?

            It's hard to explain sometimes exactly what you want to do in a script so it makes it harder to find on the internet.

            • 3. Re: Applying files in PS in bulk
              c.pfaffenbichler Level 9

              Maybe this can be useful for your case:

              Re: Batch replace smart objects

              1 person found this helpful
              • 4. Re: Applying files in PS in bulk
                Chuck Uebele Adobe Community Professional & MVP

                c.pfaffenbichler's link has a good example of how to get files from a folder and do a batch.

                • 5. Re: Applying files in PS in bulk
                  d1g1talphyre Level 1

                  ah, this is something I actually do all day. 

                   

                  So,  in photoshop start a new action, tab back to bridge, open the file.  Then go to File > Scripts > browse.  Select the script you want to run.  Let it run.  I didn't pay much attention if your script saves the files or not.  If not, save the file to the location you want.

                  Stop recording the action.

                   

                  Go to bridge, go to Tools > Photoshop > batch.  Now you can select the action you just recorded in photoshop.  A new window will pop up,  very important you select the check boxes correctly on this. 

                   

                  in the area named play, select the action you want to run.  In the "Source" area directly under it, check Override Action "Open Commands"  Suppress File open Options Dialogs, and Suppress Color Profile Warnings.  Do not check include all subfolders unless you are running this on subfolders   next in Destination: leave it to none.  Its easier to use photoshops actions or script to tell it where you want files to go. 

                   

                  Also make sure Errors: Stop for errors is selected. 

                   

                  Now, click okay, and sit back and watch.  I process hundreds or RAW phase one camera images every day, and this is by far the easiest way to size, color balance, and contrast folder after folder of images.  I hope this helps.

                  • 6. Re: Applying files in PS in bulk
                    mariap14286444 Level 1

                    This uses the 'replace smart object' command. I've not been able to find a way that will resize any placed image to fit the size the smart object was originally set at.

                    • 7. Re: Applying files in PS in bulk
                      mariap14286444 Level 1

                      I don't fully understand what you mean. I have several issues; for me, Bridge opens in a seperate window. I have Photoshop CC 2015. You say 'open a file in Bridge' - does that mean editting the smart object and then placing a file from Bridge into that smart object? I tried that and recorded it as an action but it didn't work - the batch didn't select the other designs I have in the same folder.

                      • 8. Re: Applying files in PS in bulk
                        c.pfaffenbichler Level 9

                        You could for example

                        • place the new content as a Smart Object in the SO instead of replacing it or

                        • get the bounds before replacing and after replacing and calculate the necessary scaling (Warp etc. but even an applied Rotation may be a problem, though)

                        • 9. Re: Applying files in PS in bulk
                          mariap14286444 Level 1

                          At the moment, I place the file into the smart object and save and close it.

                           

                          Is there a script that replaces a smart object to a desired size and that can pick up every other file in that folder and apply the same effect? That's all I'm really looking for.

                          • 10. Re: Applying files in PS in bulk
                            c.pfaffenbichler Level 9

                            Is there a script that replaces a smart object to a desired size and that can pick up every other file in that folder and apply the same effect?

                            Possibly, but

                            • Why don’t you take the Script from that other thread and amend to to meet your requirements?

                            • And have you clarified what you actually mean by

                            a desired size

                            ? What if the placed content has other proportions?

                            • 12. Re: Applying files in PS in bulk
                              mariap14286444 Level 1

                              Sorry but I'm not very good at scripting. I find that if I want to change something I always get an error of something I've done wrong and I don't know how to change it.

                               

                              01.PNG

                              Above - the red square shows my original smart object size.

                               

                              02.PNG

                              Above - replace smart objects makes the design too small.

                               

                              Ideally, I need it to scale to fit my original smart object size.

                              • 13. Re: Applying files in PS in bulk
                                mariap14286444 Level 1

                                Batch Replace Smart Object With Different Image Quality and Sizes

                                I've tried this script and I'm not experienced enough to edit the errors they are discussing.

                                • 14. Re: Applying files in PS in bulk
                                  c.pfaffenbichler Level 9

                                  The Script in post 3 has one mistake in the line

                                  var theFactor = (Number(theBounds[2])-Number(theBounds[0]))/(Number(newBounds[2])-Number(newBounds[0]))*1 00;

                                  A superfluous space in the number "100".

                                  • 15. Re: Applying files in PS in bulk
                                    mariap14286444 Level 1

                                    It still isn't doing what I wanted. It also uses the replace smart object command, which makes the design smaller as I showed in the images above.

                                    • 16. Re: Applying files in PS in bulk
                                      c.pfaffenbichler Level 9

                                      Are you talking about the Script from post 3 of this thread?

                                      Batch Replace Smart Object With Different Image Quality and Sizes

                                      If so please provide the image with the SO and a couple of files you are trying to switch in.

                                      • 17. Re: Applying files in PS in bulk
                                        c.pfaffenbichler Level 9

                                        That Script scales the replaced SO to the original SO’s width (based on the bounds), so the second screenshot in post 12 seems somewhat implausible unless the placed SO has stray pixels or other issues.

                                        • 18. Re: Applying files in PS in bulk
                                          mariap14286444 Level 1

                                          The pictures I posted were from using that script. The canvas size of my smart object is 547 x 623 pixels. The picture I am trying to place is 2283 x 3463 pixels. But my designs have a maximum size for printing and can change to a smaller size depending on the design.

                                          • 19. Re: Applying files in PS in bulk
                                            c.pfaffenbichler Level 9
                                            please provide the image with the SO and a couple of files you are trying to switch in.
                                            • 20. Re: Applying files in PS in bulk
                                              mariap14286444 Level 1

                                              ok so I have a script that opens the smart object. Before I run that script, I want to select a file that I ultimately want in that smart object. I then want the smart object to save and close, and then to run my 'save each group as a JPEG' script. I want to be able to do this in bulk so I have N files in a folder that can be processed through the smart object and saved as JPEGs.

                                               

                                              Sorry for the very long winded explanations. I really appreciate the help.

                                              • 21. Re: Applying files in PS in bulk
                                                c.pfaffenbichler Level 9
                                                please provide the image with the SO and a couple of files you are trying to switch in.
                                                • 22. Re: Applying files in PS in bulk
                                                  mariap14286444 Level 1

                                                  picture.jpg

                                                   

                                                  So on the left I have the five files I want to insert into the smart layer on the right, and ultimately save and apply to the middle file.

                                                  • 23. Re: Applying files in PS in bulk
                                                    c.pfaffenbichler Level 9
                                                    // select files and place in a selected smart object;
                                                    // to cause the so in the so to be scaled to fit the resolution is temprarily changed, but this is no guarantee for this to happen;
                                                    // 2015, use it at your own risk;
                                                    #target photoshop
                                                    if (app.documents.length > 0) {
                                                    var myDocument = app.activeDocument;
                                                    var theName= myDocument.name.match(/(.*)\.[^\.]+$/)[1];
                                                    var thePath = myDocument.path;
                                                    var theLayer = myDocument.activeLayer;
                                                    // psd options;
                                                    psdOpts = new PhotoshopSaveOptions();
                                                    psdOpts.embedColorProfile = true;
                                                    psdOpts.alphaChannels = true;
                                                    psdOpts.layers = true;
                                                    psdOpts.spotColors = true;
                                                    // check if layer is smart object;
                                                    if (theLayer.kind != "LayerKind.SMARTOBJECT") {alert ("selected layer is not a smart object")}
                                                    else {
                                                    if ($.os.search(/windows/i) != -1) {var theFiles = File.openDialog ("please select files", "*.pdf;*.ai;*.psd;*.tif", true)}
                                                    else {var theFiles = File.openDialog ("please select files", getFiles, true)};
                                                    if (theFiles) {
                                                    // set to pixels;
                                                    var originalRulerUnits = app.preferences.rulerUnits;
                                                    app.preferences.rulerUnits = Units.PIXELS;
                                                    // get bounds;
                                                    var theBounds = theLayer.bounds;
                                                    // work through the array;
                                                    for (var m = 0; m < theFiles.length; m++) {
                                                    var theNewName = File(theFiles[m]).name.match(/(.*)\.[^\.]+$/)[1];
                                                    // replace smart object;
                                                    placeSmartObjectInSmartObject(app.activeDocument.activeLayer, theFiles[m]);
                                                    //save psd;
                                                    myDocument.saveAs((new File(thePath+"/"+theName+"_"+theNewName+".psd")),psdOpts,true);
                                                    // undo;
                                                    myDocument.activeHistoryState = myDocument.historyStates[myDocument.historyStates.length-2]
                                                    };
                                                    // reset;
                                                    originalRulerUnits = app.preferences.rulerUnits;
                                                    }
                                                    }
                                                    };
                                                    ////// open smart object //////
                                                    function placeSmartObjectInSmartObject (theLayer, thisFile) {
                                                    if (theLayer.kind == "LayerKind.SMARTOBJECT") {
                                                    // get prefernces setting;
                                                    var ref = new ActionReference();
                                                    ref.putProperty(stringIDToTypeID("property"), stringIDToTypeID("generalPreferences"));
                                                    ref.putEnumerated( charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
                                                    var applicationDesc = executeActionGet(ref);
                                                    var generalDesc = applicationDesc.getObjectValue(stringIDToTypeID("generalPreferences"));
                                                    var resizeDuringPlace = generalDesc.getBoolean(stringIDToTypeID("resizePastePlace"));
                                                    if (resizeDuringPlace == false) {
                                                    // =======================================================
                                                    var idsetd = charIDToTypeID( "setd" );
                                                        var desc1 = new ActionDescriptor();
                                                        var idnull = charIDToTypeID( "null" );
                                                            var ref1 = new ActionReference();
                                                            var idPrpr = charIDToTypeID( "Prpr" );
                                                            var idGnrP = charIDToTypeID( "GnrP" );
                                                            ref1.putProperty( idPrpr, idGnrP );
                                                            var idcapp = charIDToTypeID( "capp" );
                                                            var idOrdn = charIDToTypeID( "Ordn" );
                                                            var idTrgt = charIDToTypeID( "Trgt" );
                                                            ref1.putEnumerated( idcapp, idOrdn, idTrgt );
                                                        desc1.putReference( idnull, ref1 );
                                                        var idT = charIDToTypeID( "T  " );
                                                            var desc2 = new ActionDescriptor();
                                                            var idresizePastePlace = stringIDToTypeID( "resizePastePlace" );
                                                            desc2.putBoolean( idresizePastePlace, true );
                                                            var idlegacyPathDrag = stringIDToTypeID( "legacyPathDrag" );
                                                            desc2.putBoolean( idlegacyPathDrag, true );
                                                        var idGnrP = charIDToTypeID( "GnrP" );
                                                        desc1.putObject( idT, idGnrP, desc2 );
                                                    executeAction( idsetd, desc1, DialogModes.NO );
                                                    };
                                                    // =======================================================
                                                    var idplacedLayerEditContents = stringIDToTypeID( "placedLayerEditContents" );
                                                        var desc2 = new ActionDescriptor();
                                                    executeAction( idplacedLayerEditContents, desc2, DialogModes.NO );
                                                    // set to high resolution to make scaling on placing probable;
                                                    var theResolution = activeDocument.resolution;
                                                    activeDocument.resizeImage(undefined, undefined, 3000, ResampleMethod.NONE);
                                                    // place so;
                                                    // =======================================================
                                                    var idPlc = charIDToTypeID( "Plc " );
                                                        var desc4 = new ActionDescriptor();
                                                        var idAs = charIDToTypeID( "As  " );
                                                            var desc5 = new ActionDescriptor();
                                                            var idfsel = charIDToTypeID( "fsel" );
                                                            var idpdfSelection = stringIDToTypeID( "pdfSelection" );
                                                            var idpage = stringIDToTypeID( "page" );
                                                            desc5.putEnumerated( idfsel, idpdfSelection, idpage );
                                                            var idPgNm = charIDToTypeID( "PgNm" );
                                                            desc5.putInteger( idPgNm, 1 );
                                                            var idCrop = charIDToTypeID( "Crop" );
                                                            var idcropTo = stringIDToTypeID( "cropTo" );
                                                            var idtrimBox = stringIDToTypeID( "trimBox" );
                                                            desc5.putEnumerated( idCrop, idcropTo, idtrimBox );
                                                        var idPDFG = charIDToTypeID( "PDFG" );
                                                        desc4.putObject( idAs, idPDFG, desc5 );
                                                        var idnull = charIDToTypeID( "null" );
                                                        desc4.putPath( idnull, new File( thisFile ) );
                                                        var idFTcs = charIDToTypeID( "FTcs" );
                                                        var idQCSt = charIDToTypeID( "QCSt" );
                                                        var idQcsa = charIDToTypeID( "Qcsa" );
                                                        desc4.putEnumerated( idFTcs, idQCSt, idQcsa );
                                                        var idOfst = charIDToTypeID( "Ofst" );
                                                            var desc6 = new ActionDescriptor();
                                                            var idHrzn = charIDToTypeID( "Hrzn" );
                                                            var idRlt = charIDToTypeID( "#Rlt" );
                                                            desc6.putUnitDouble( idHrzn, idRlt, 0.000000 );
                                                            var idVrtc = charIDToTypeID( "Vrtc" );
                                                            var idRlt = charIDToTypeID( "#Rlt" );
                                                            desc6.putUnitDouble( idVrtc, idRlt, 0.000000 );
                                                        var idOfst = charIDToTypeID( "Ofst" );
                                                        desc4.putObject( idOfst, idOfst, desc6 );
                                                        var idAntA = charIDToTypeID( "AntA" );
                                                        desc4.putBoolean( idAntA, true );
                                                    executeAction( idPlc, desc4, DialogModes.NO );
                                                    // toggle visibility of others;
                                                    // =======================================================
                                                    var idShw = charIDToTypeID( "Shw " );
                                                        var desc10 = new ActionDescriptor();
                                                        var idnull = charIDToTypeID( "null" );
                                                            var list4 = new ActionList();
                                                                var ref7 = new ActionReference();
                                                                var idLyr = charIDToTypeID( "Lyr " );
                                                                var idOrdn = charIDToTypeID( "Ordn" );
                                                                var idTrgt = charIDToTypeID( "Trgt" );
                                                                ref7.putEnumerated( idLyr, idOrdn, idTrgt );
                                                            list4.putReference( ref7 );
                                                        desc10.putList( idnull, list4 );
                                                        var idTglO = charIDToTypeID( "TglO" );
                                                        desc10.putBoolean( idTglO, true );
                                                    executeAction( idShw, desc10, DialogModes.NO );
                                                    // reset resolution;
                                                    activeDocument.resizeImage(undefined, undefined, theResolution, ResampleMethod.NONE);
                                                    // close;
                                                    app.activeDocument.close(SaveOptions.SAVECHANGES)
                                                    };
                                                    };
                                                    ////// get psds, tifs and jpgs from files //////
                                                    function getFiles (theFile) {
                                                    if (theFile.name.match(/\.(pdf|ai|jpg|tif|psb|psd)$/i)) {
                                                    return true
                                                    };
                                                    };
                                                    
                                                    • 24. Re: Applying files in PS in bulk
                                                      mariap14286444 Level 1

                                                      hi,

                                                       

                                                      thanks for the script. It opens the smart layer and I select a file to place into it, but it doesn't save with that new file.

                                                      Also if I have five designs, how can I set this to run a batch - go through all five with the results?

                                                      • 25. Re: Applying files in PS in bulk
                                                        c.pfaffenbichler Level 9

                                                        It opens the smart layer and I select a file to place into it, but it doesn't save with that new file.

                                                        First one selects as many files as one wants, after that the SO will be opened.

                                                        And psd copies with the amended Smart Object are saved.

                                                        • 26. Re: Applying files in PS in bulk
                                                          mariap14286444 Level 1

                                                          Hi,

                                                           

                                                          I understand. The PSD files are now just showing the original design, not the ones I select during the script run.

                                                          • 27. Re: Applying files in PS in bulk
                                                            c.pfaffenbichler Level 9

                                                            With my test files no such problem has turned up.

                                                            I have asked for your files to test three times and you have not complied – why?


                                                            Stop the Script after line 31 – in the History a Smart Object update should be indicated, what is its result?

                                                            • 28. Re: Applying files in PS in bulk
                                                              mariap14286444 Level 1

                                                              Hi,

                                                              don't know what happened there but the error hasn't occurred again.

                                                              c.pfaffenbichler wrote:


                                                              Stop the Script after line 31 – in the History a Smart Object update should be indicated, what is its result?


                                                              I don't mean to be rude I just don't understand what you mean.

                                                               

                                                               

                                                              I have removed line 31 and inserted my JPEG script and it works fine. I just need to make tweeks on it.

                                                               

                                                               

                                                               

                                                              When your original script saved the PSD file, it used the name of the PNG file in the title.

                                                               

                                                              My original script uses the group name in the save name.

                                                               

                                                              Is there a way to get both?

                                                               

                                                              Your original script:

                                                               

                                                              myDocument.saveAs((new File(thePath+"/"+theName+"_"+theNewName+".psd")),psdOpts,true);


                                                              My original script:

                                                               

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

                                                               

                                                               

                                                              When I save in bulk, it replaces the other JPEGs with the newest one, so I still only have one saved design. I want the group layer name saved like my original, but I want your PNG file name on it too. Is that possible?


                                                              • 29. Re: Applying files in PS in bulk
                                                                c.pfaffenbichler Level 9
                                                                I don't mean to be rude I just don't understand what you mean.

                                                                I meant to stop the Script after line 31 and see in the History whether the Smart Object has been updated with new content or not.

                                                                If not the saving step after that would result in the identically appearing files you described – a behaviour I had not observed.

                                                                afterUpdate.png

                                                                • 30. Re: Applying files in PS in bulk
                                                                  mariap14286444 Level 1

                                                                  I'm not sure what was going on wrong but the error hasn't occured again. Maybe I was doing it wrong but it's working now.

                                                                   

                                                                  But is there a way to get both the file name from your script and the group name from my script into the saved file name?

                                                                   

                                                                  Your original script:

                                                                   

                                                                  myDocument.saveAs((new File(thePath+"/"+theName+"_"+theNewName+".psd")),psdOpts,true);


                                                                  My original script:

                                                                   

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

                                                                  • 31. Re: Applying files in PS in bulk
                                                                    mariap14286444 Level 1

                                                                    c.pfaffenbichler I want to thank you so much for taking your time out to help me. I can't tell you how easy you've made this job for me. I'm so grateful for your kind help, thank you!!

                                                                    • 32. Re: Applying files in PS in bulk
                                                                      mariap14286444 Level 1
                                                                      // select files and place in a selected smart object; 
                                                                      // to cause the so in the so to be scaled to fit the

                                                                       

                                                                      resolution is temprarily changed, but this is no guarantee for

                                                                       

                                                                      this to happen; 

                                                                      // 2015, use it at your own risk; 
                                                                      #target photoshop 
                                                                      if (app.documents.length > 0) { 
                                                                      var myDocument = app.activeDocument; 
                                                                      var theName= myDocument.name.match(/(.*)\.[^\.]+$/)[1]; 
                                                                      var thePath = myDocument.path; 
                                                                      var theLayer = myDocument.activeLayer; 
                                                                      // psd options; 
                                                                      psdOpts = new PhotoshopSaveOptions(); 
                                                                      psdOpts.embedColorProfile = true; 
                                                                      psdOpts.alphaChannels = true; 
                                                                      psdOpts.layers = true; 
                                                                      psdOpts.spotColors = true; 
                                                                      // check if layer is smart object; 
                                                                      if (theLayer.kind != "LayerKind.SMARTOBJECT") {alert

                                                                       

                                                                      ("selected layer is not a smart object")} 

                                                                      else { 
                                                                      if ($.os.search(/windows/i) != -1) {var theFiles =

                                                                       

                                                                      File.openDialog ("please select files",

                                                                       

                                                                      "*.pdf;*.ai;*.psd;*.tif;*.png", true)} 

                                                                      else {var theFiles = File.openDialog ("please select

                                                                       

                                                                      files", getFiles, true)}; 

                                                                      if (theFiles) { 
                                                                      // set to pixels; 
                                                                      var originalRulerUnits = app.preferences.rulerUnits; 
                                                                      app.preferences.rulerUnits = Units.PIXELS; 
                                                                      // get bounds; 
                                                                      var theBounds = theLayer.bounds; 
                                                                      // work through the array; 
                                                                      for (var m = 0; m < theFiles.length; m++) { 
                                                                      var theNewName = File(theFiles[m]).name.match(/(.*)\.[^

                                                                       

                                                                      \.]+$/)[1]; 

                                                                      // replace smart object; 
                                                                      placeSmartObjectInSmartObject

                                                                       

                                                                      (app.activeDocument.activeLayer, theFiles[m]); 

                                                                      #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(); 
                                                                              activeDocument.trim

                                                                       

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

                                                                          var saveFile= File(oldPath+"/PRE-NAME"+theNewName

                                                                       

                                                                      +"-"+doc.layerSets[a].name +".jpg");

                                                                           saveJPG(saveFile,10); 

                                                                              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 saveJPG(saveFile, jpegQuality) { 
                                                                          app.activeDocument.flatten();  
                                                                          jpgSaveOptions = new JPEGSaveOptions(); 
                                                                          jpgSaveOptions.embedColorProfile = true; 
                                                                          jpgSaveOptions.formatOptions =

                                                                       

                                                                      FormatOptions.STANDARDBASELINE; 

                                                                          jpgSaveOptions.matte = MatteType.NONE; 
                                                                          jpgSaveOptions.quality = jpegQuality; //1-12 
                                                                          activeDocument.saveAs(saveFile, jpgSaveOptions,

                                                                       

                                                                      true,Extension.LOWERCASE); 

                                                                      // undo; 

                                                                      myDocument.activeHistoryState = myDocument.historyStates

                                                                       

                                                                      [myDocument.historyStates.length-2] 

                                                                      }; 

                                                                      // reset; 

                                                                      originalRulerUnits = app.preferences.rulerUnits; 

                                                                      }; 

                                                                      ////// open smart object ////// 
                                                                      function placeSmartObjectInSmartObject (theLayer, thisFile)

                                                                       

                                                                      if (theLayer.kind == "LayerKind.SMARTOBJECT") { 
                                                                      // get prefernces setting; 
                                                                      var ref = new ActionReference(); 
                                                                      ref.putProperty(stringIDToTypeID("property"),

                                                                       

                                                                      stringIDToTypeID("generalPreferences")); 

                                                                      ref.putEnumerated( charIDToTypeID("capp"), charIDToTypeID

                                                                       

                                                                      ("Ordn"), charIDToTypeID("Trgt") ); 

                                                                      var applicationDesc = executeActionGet(ref); 
                                                                      var generalDesc = applicationDesc.getObjectValue

                                                                       

                                                                      (stringIDToTypeID("generalPreferences")); 

                                                                      var resizeDuringPlace = generalDesc.getBoolean

                                                                       

                                                                      (stringIDToTypeID("resizePastePlace")); 

                                                                      if (resizeDuringPlace == false) { 
                                                                      // ======================================================= 
                                                                      var idsetd = charIDToTypeID( "setd" ); 
                                                                          var desc1 = new ActionDescriptor(); 
                                                                          var idnull = charIDToTypeID( "null" ); 
                                                                              var ref1 = new ActionReference(); 
                                                                              var idPrpr = charIDToTypeID( "Prpr" ); 
                                                                              var idGnrP = charIDToTypeID( "GnrP" ); 
                                                                              ref1.putProperty( idPrpr, idGnrP ); 
                                                                              var idcapp = charIDToTypeID( "capp" ); 
                                                                              var idOrdn = charIDToTypeID( "Ordn" ); 
                                                                              var idTrgt = charIDToTypeID( "Trgt" ); 
                                                                              ref1.putEnumerated( idcapp, idOrdn, idTrgt ); 
                                                                          desc1.putReference( idnull, ref1 ); 
                                                                          var idT = charIDToTypeID( "T  " ); 
                                                                              var desc2 = new ActionDescriptor(); 
                                                                              var idresizePastePlace = stringIDToTypeID(

                                                                       

                                                                      "resizePastePlace" ); 

                                                                              desc2.putBoolean( idresizePastePlace, true ); 
                                                                              var idlegacyPathDrag = stringIDToTypeID(

                                                                       

                                                                      "legacyPathDrag" ); 

                                                                              desc2.putBoolean( idlegacyPathDrag, true ); 
                                                                          var idGnrP = charIDToTypeID( "GnrP" ); 
                                                                          desc1.putObject( idT, idGnrP, desc2 ); 
                                                                      executeAction( idsetd, desc1, DialogModes.NO ); 
                                                                      }; 
                                                                      // ======================================================= 
                                                                      var idplacedLayerEditContents = stringIDToTypeID(

                                                                       

                                                                      "placedLayerEditContents" ); 

                                                                          var desc2 = new ActionDescriptor(); 
                                                                      executeAction( idplacedLayerEditContents, desc2,

                                                                       

                                                                      DialogModes.NO ); 

                                                                      // set to high resolution to make scaling on placing

                                                                       

                                                                      probable; 

                                                                      var theResolution = activeDocument.resolution; 
                                                                      activeDocument.resizeImage(undefined, undefined, 3000,

                                                                       

                                                                      ResampleMethod.NONE); 

                                                                      // place so; 
                                                                      // ======================================================= 
                                                                      var idPlc = charIDToTypeID( "Plc " ); 
                                                                          var desc4 = new ActionDescriptor(); 
                                                                          var idAs = charIDToTypeID( "As  " ); 
                                                                              var desc5 = new ActionDescriptor(); 
                                                                              var idfsel = charIDToTypeID( "fsel" ); 
                                                                              var idpdfSelection = stringIDToTypeID(

                                                                       

                                                                      "pdfSelection" ); 

                                                                              var idpage = stringIDToTypeID( "page" ); 
                                                                              desc5.putEnumerated( idfsel, idpdfSelection, idpage

                                                                       

                                                                      ); 

                                                                              var idPgNm = charIDToTypeID( "PgNm" ); 
                                                                              desc5.putInteger( idPgNm, 1 ); 
                                                                              var idCrop = charIDToTypeID( "Crop" ); 
                                                                              var idcropTo = stringIDToTypeID( "cropTo" ); 
                                                                              var idtrimBox = stringIDToTypeID( "trimBox" ); 
                                                                              desc5.putEnumerated( idCrop, idcropTo, idtrimBox );

                                                                       

                                                                       

                                                                          var idPDFG = charIDToTypeID( "PDFG" ); 
                                                                          desc4.putObject( idAs, idPDFG, desc5 ); 
                                                                          var idnull = charIDToTypeID( "null" ); 
                                                                          desc4.putPath( idnull, new File( thisFile ) ); 
                                                                          var idFTcs = charIDToTypeID( "FTcs" ); 
                                                                          var idQCSt = charIDToTypeID( "QCSt" ); 
                                                                          var idQcsa = charIDToTypeID( "Qcsa" ); 
                                                                          desc4.putEnumerated( idFTcs, idQCSt, idQcsa ); 
                                                                          var idOfst = charIDToTypeID( "Ofst" ); 
                                                                              var desc6 = new ActionDescriptor(); 
                                                                              var idHrzn = charIDToTypeID( "Hrzn" ); 
                                                                              var idRlt = charIDToTypeID( "#Rlt" ); 
                                                                              desc6.putUnitDouble( idHrzn, idRlt, 0.000000 ); 
                                                                              var idVrtc = charIDToTypeID( "Vrtc" ); 
                                                                              var idRlt = charIDToTypeID( "#Rlt" ); 
                                                                              desc6.putUnitDouble( idVrtc, idRlt, 0.000000 ); 
                                                                          var idOfst = charIDToTypeID( "Ofst" ); 
                                                                          desc4.putObject( idOfst, idOfst, desc6 ); 
                                                                          var idAntA = charIDToTypeID( "AntA" ); 
                                                                          desc4.putBoolean( idAntA, true ); 
                                                                      executeAction( idPlc, desc4, DialogModes.NO ); 
                                                                      // toggle visibility of others; 
                                                                      // ======================================================= 
                                                                      var idShw = charIDToTypeID( "Shw " ); 
                                                                          var desc10 = new ActionDescriptor(); 
                                                                          var idnull = charIDToTypeID( "null" ); 
                                                                              var list4 = new ActionList(); 
                                                                                  var ref7 = new ActionReference(); 
                                                                                  var idLyr = charIDToTypeID( "Lyr " ); 
                                                                                  var idOrdn = charIDToTypeID( "Ordn" ); 
                                                                                  var idTrgt = charIDToTypeID( "Trgt" ); 
                                                                                  ref7.putEnumerated( idLyr, idOrdn, idTrgt ); 
                                                                              list4.putReference( ref7 ); 
                                                                          desc10.putList( idnull, list4 ); 
                                                                          var idTglO = charIDToTypeID( "TglO" ); 
                                                                          desc10.putBoolean( idTglO, true ); 
                                                                      executeAction( idShw, desc10, DialogModes.NO ); 
                                                                      // reset resolution; 
                                                                      activeDocument.resizeImage(undefined, undefined,

                                                                       

                                                                      theResolution, ResampleMethod.NONE); 

                                                                      // close; 
                                                                      app.activeDocument.close(SaveOptions.SAVECHANGES) 
                                                                      }; 
                                                                      }; 
                                                                      ////// get psds, tifs and jpgs from files ////// 
                                                                      function getFiles (theFile) { 
                                                                      if (theFile.name.match(/\.(pdf|ai|jpg|tif|psb|psd)$/i)) { 
                                                                      return true 
                                                                      }; 
                                                                      };