Export Groups to Files?

New Here ,
Sep 06, 2009

Copy link to clipboard

Copied

Is there a way to export multiple GROUPS into individual files, such as jpg?  If I run the File > Scripts > Export LAYERS To Files, each LAYER becomes a jpeg, but i'd like each GROUP to be flattened and exported as a jpg. Is there a script or funtion that performs this task?

Topics

Actions and scripting

Views

90.2K

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
New Here ,
Feb 02, 2011

Copy link to clipboard

Copied

Great scripts.

I have no idea how Photoshop scripts work, but i would be very happe if someone could tweak the script so it only selects the root groups and esports if for jpgs.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
New Here ,
May 19, 2011

Copy link to clipboard

Copied

Or if someone can have one that saves it as PSD... trimmed... can someone hook me up with that script? I'll send you some Paypal beer donation. Thanks in advance!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Valorous Hero ,
May 19, 2011

Copy link to clipboard

Copied

This should now save as a PSD ...

#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.name);
dupLayers();
activeDocument.mergeVisibleLayers();
activeDocument.trim(TrimType.TRANSPARENT,true...
.name +".psd");
SavePSD(saveFile);
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
    }
}
main()...
















Likes

1 Like

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
New Here ,
May 19, 2011

Copy link to clipboard

Copied

Hey thanks for the quick reply. However I am getting an error message and I am not getting prompted with the dialogue box to choose which ones I want to extract ...

here is the error message

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
New Here ,
May 19, 2011

Copy link to clipboard

Copied

Screen shot 2011-05-19 at 6.00.55 PM.jpg

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Valorous Hero ,
May 19, 2011

Copy link to clipboard

Copied

This script isn't written for selected layersets, it does them all.

If you want to save selected layers/layersets this script might do the job as it support layers and layerset and persistant Top/Background layers.


#target photoshop
function main(){
var LSets = activeDocument.layerSets.length;
var ArtLayers = activeDocument.artLayers.length;
var NoOfLayers = activeDocument.layers.length;
var Back = hasBackground();
var hasTop = false;
var selLayers =getSelectedLayersIdx();
var selGroups=[];
if(LSets>0){
    for(var s in selLayers){
   if(isLayerSet(selLayers)) selGroups.push(selLayers);
        }
    }
if(activeDocument.layers[0].typename == 'ArtLayer') hasTop = true;
var win = new Window('dialog','Layer Saver');
g = win.graphics;
var myBrush = g.newBrush(g.BrushType.SOLID_COLOR, [0.99, 0.99, 0.99, 1]);
g.backgroundColor = myBrush;

win.p1= win.add("panel", undefined, undefined, {borderStyle:"black"});
win.p1.preferredSize=[500,20];
win.g1 = win.p1.add('group');
win.g1.orientation = "row";
win.title = win.g1.add('statictext',undefined,'Layer Saver');
win.title.alignment="fill";
var g = win.title.graphics;
g.font = ScriptUI.newFont("Georgia","BOLDITALIC",22);
win.g5 =win.p1.add('group');
win.g5.orientation = "column";
win.g5.alignChildren='left';
win.g5.spacing=0;
if(LSets == 0){
win.g5.rb1 = win.g5.add('radiobutton',undefined,'Save selected layers');
win.g5.rb2 = win.g5.add('radiobutton',undefined,'Save selected layers along with the top layer');
win.g5.rb3 = win.g5.add('radiobutton',undefined,'Save selected layers along with background layer');
win.g5.rb4 = win.g5.add('radiobutton',undefined,'Save all layers');
win.g5.rb5 = win.g5.add('radiobutton',undefined,'Save all layers along with the top layer');
win.g5.rb6 = win.g5.add('radiobutton',undefined,'Save all layers along with background layer');
win.g5.rb3.enabled=Back;
win.g5.rb6.enabled=Back;
win.g5.rb4.value=true;
}else{
win.g5.rb1 = win.g5.add('radiobutton',undefined,'Save selected layerSets');
win.g5.rb2 = win.g5.add('radiobutton',undefined,'Save selected layerSets along with the top layer');
win.g5.rb3 = win.g5.add('radiobutton',undefined,'Save selected layerSets along with background layer');
win.g5.rb4 = win.g5.add('radiobutton',undefined,'Save all layerSets');
win.g5.rb5 = win.g5.add('radiobutton',undefined,'Save all layerSets along with the top layer');
win.g5.rb6 = win.g5.add('radiobutton',undefined,'Save all layerSets along with background layer');
win.g5.rb3.enabled=Back;
win.g5.rb6.enabled=Back;
win.g5.rb2.enabled=hasTop;
win.g5.rb5.enabled=hasTop;
if(selGroups.length <1){
    win.g5.rb1.enabled=false;
    win.g5.rb2.enabled=false;
    win.g5.rb3.enabled=false;
    }
win.g5.rb4.value=true;
    }
win.p2 = win.add("panel", undefined, undefined, {borderStyle:"black"});
win.p2.preferredSize=[500,20];
win.p2.st1 = win.p2.add('statictext',undefined,'Output details');
win.p2.st1.graphics.font = ScriptUI.newFont("Tahoma", "Bold", 18);
win.g10 =win.p2.add('group');
win.g10.orientation = "row";
win.g10.alignment='left';
win.g10.et1 = win.g10.add('edittext');
win.g10.et1.preferredSize=[350,20];
win.g10.bu1 = win.g10.add('button',undefined,'Select Folder');
win.g10.bu1.onClick=function(){
var Folder1 = Folder(app.activeDocument.path);
outputFolder = Folder.selectDialog("Please select the output folder",Folder1);
if(outputFolder !=null){
  win.g10.et1.text =  decodeURI(outputFolder.fsName);
  }
}
win.g12 =win.p2.add('group');
win.g12.orientation = "row";
win.g12.alignment='left';
win.g12.cb1 = win.g12.add('checkbox',undefined,'Merge Visible Layers?');
win.g12.cb2 = win.g12.add('checkbox',undefined,'Trim Layer');

win.g15 =win.p2.add('group');
win.g15.orientation = "row";
win.g15.alignment='left';
var Options= ["Layer/Group Name","FileName + Sequence No.","FileName + Layer/Group Name ","User Defined with Sequence No."];
win.g15.st1 = win.g15.add('statictext',undefined,'Save Options..');
win.g15.dd1 = win.g15.add('dropdownlist',undefined,Options);
win.g15.dd1.selection=0;
win.g15.et1 = win.g15.add('edittext');
win.g15.et1.preferredSize=[150,20];
win.g15.et1.hide();
win.g15.dd1.onChange=function(){
  if(this.selection.index==3){
      win.g15.et1.show();
      }else{
          win.g15.et1.hide();
          }
    }
win.g18 =win.p2.add('group');
win.g18.orientation = "row";
win.g18.st1 = win.g18.add('statictext',undefined,'Save as :');
var Types = ["PNG","PSD","PDF","TIF","JPG"];
win.g18.dd1 = win.g18.add('dropdownlist',undefined,Types);
win.g18.dd1.selection = 0;
win.g18.alignment='left';
win.g20 =win.p2.add('group');
win.g20.orientation = "row";
win.g20.bu1 = win.g20.add('button',undefined,'Process');
win.g20.bu1.preferredSize=[200,35];
win.g20.bu2 = win.g20.add('button',undefined,'Cancel');
win.g20.bu2.preferredSize=[200,35];
win.g20.bu1.onClick=function(){
    if(win.g10.et1.text == ''){
        alert("No Output Folder has been Selected!");
        return;
        }
    if(win.g15.dd1.selection.index==3){
        if(win.g15.et1.text ==''){
            alert("No FileName Has Been Entered!");
            return;
            }
        }
    win.close(1);
Process();
}
win.center();
win.show();
function Process(){
if(LSets == 0){
//Process layers only
if(win.g5.rb1.value){//Save selected layers
for(var b in selLayers){
    selectLayerByIndex(Number(selLayers));
     var lName = activeDocument.activeLayer.name;
    var saveFile= File(outputFolder+ "/" + getName(b,lName));
    dupLayers();
    if(win.g12.cb1.value){
        try{activeDocument.mergeVisibleLayers();}catch(e){}
        }
     if(win.g12.cb2.value){
         try{activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true);}catch(e){}
         }
    SaveDOC(saveFile);
    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
    }
    }//End Save selected layers
if(win.g5.rb2.value){//Save selected layers along with the top layer
for(var b in selLayers){
    selectLayerByIndex(Number(selLayers));
     var lName = activeDocument.activeLayer.name;
    activeDocument.activeLayer= activeDocument.layers[0];
    selectLayerByIndex(Number(selLayers),true);
    var saveFile= File(outputFolder+ "/" + getName(b,lName));
    dupLayers();
    if(win.g12.cb1.value){
        try{activeDocument.mergeVisibleLayers();}catch(e){}
        }
    if(win.g12.cb2.value){
         try{activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true);}catch(e){}
         }
    SaveDOC(saveFile);
    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
    }
    }//End Save selected layers along with the top layer
if(win.g5.rb3.value){//Save selected layers along with background layer
    for(var b in selLayers){
    selectLayerByIndex(Number(selLayers));
     var lName = activeDocument.activeLayer.name;
    activeDocument.activeLayer = activeDocument.layers[activeDocument.layers.length-1];
    selectLayerByIndex(Number(selLayers),true);
    var saveFile= File(outputFolder+ "/" + getName(b,lName));
    dupLayers();
        if(win.g12.cb1.value){
        try{activeDocument.mergeVisibleLayers();}catch(e){}
        }
    if(win.g12.cb2.value){
         try{activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true);}catch(e){}
         }
    SaveDOC(saveFile);
    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
    }
    }//End Save selected layers along with background layer
if(win.g5.rb4.value){//Save all layers
selectAllLayers();
selLayers =getSelectedLayersIdx();
for(var b in selLayers){
     selectLayerByIndex(Number(selLayers));
     var lName = activeDocument.activeLayer.name;
    var saveFile= File(outputFolder+ "/" + getName(b,lName));
    dupLayers();
        if(win.g12.cb1.value){
        try{activeDocument.mergeVisibleLayers();}catch(e){}
        }
    if(win.g12.cb2.value){
         try{activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true);}catch(e){}
         }
    SaveDOC(saveFile);
    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
     }
    }//End Save all layers
if(win.g5.rb5.value){//Save all layers along with the top layer
selectAllLayers(1);
selLayers =getSelectedLayersIdx();
for(var b in selLayers){
    selectLayerByIndex(Number(selLayers));
     var lName = activeDocument.activeLayer.name;
    activeDocument.activeLayer = activeDocument.layers[0];
    selectLayerByIndex(Number(selLayers),true);
    var saveFile= File(outputFolder+ "/" + getName(b,lName));
    dupLayers();
        if(win.g12.cb1.value){
        try{activeDocument.mergeVisibleLayers();}catch(e){}
        }
    if(win.g12.cb2.value){
         try{activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true);}catch(e){}
         }
    SaveDOC(saveFile);
    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
    }
    }//End Save all layers along with the top layer
if(win.g5.rb6.value){//Save all layers along with background layer
selectAllLayers();
selLayers =getSelectedLayersIdx();
    for(var b in selLayers){
    selectLayerByIndex(Number(selLayers));
     var lName = activeDocument.activeLayer.name;
    activeDocument.activeLayer = activeDocument.layers[activeDocument.layers.length-1];
    selectLayerByIndex(Number(selLayers),true);
    var saveFile= File(outputFolder+ "/" + getName(b,lName));
    dupLayers();
        if(win.g12.cb1.value){
        try{activeDocument.mergeVisibleLayers();}catch(e){}
        }
    if(win.g12.cb2.value){
         try{activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true);}catch(e){}
         }
    SaveDOC(saveFile);
    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
    }
    }//End Save all layers along with background layer
    }else{
//Process LayerSets Only
if(win.g5.rb1.value){//Save selected layerSets
    for(var g in selGroups){
        selectLayerByIndex(Number(selGroups));
        var lName = activeDocument.activeLayer.name;
        var saveFile= File(outputFolder+ "/" + getName(g,lName));
        dupLayers();
            if(win.g12.cb1.value){
        try{activeDocument.mergeVisibleLayers();}catch(e){}
        }
    if(win.g12.cb2.value){
         try{activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true);}catch(e){}
         }
    SaveDOC(saveFile);
    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
        }
   }//End Save selected layerSets
if(win.g5.rb2.value){//Save selected layerSets along with the top layer
    for(var g in selGroups){
        selectLayerByIndex(Number(selGroups));
     var lName = activeDocument.activeLayer.name;
    activeDocument.activeLayer= activeDocument.layers[0];
    selectLayerByIndex(Number(selGroups),true);
    var saveFile= File(outputFolder+ "/" + getName(g,lName));
    dupLayers();
        if(win.g12.cb1.value){
        try{activeDocument.mergeVisibleLayers();}catch(e){}
        }
    if(win.g12.cb2.value){
         try{activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true);}catch(e){}
         }
    SaveDOC(saveFile);
    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
        }
    }//End Save selected layerSets along with the top layer
if(win.g5.rb3.value){//Save selected layerSets along with background layer
    for(var g in selGroups){
    selectLayerByIndex(Number(selGroups));
     var lName = activeDocument.activeLayer.name;
    activeDocument.activeLayer = activeDocument.layers[activeDocument.layers.length-1];
    selectLayerByIndex(Number(selGroups),true);
    var saveFile= File(outputFolder+ "/" + getName(g,lName));
    dupLayers();
        if(win.g12.cb1.value){
        try{activeDocument.mergeVisibleLayers();}catch(e){}
        }
    if(win.g12.cb2.value){
         try{activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true);}catch(e){}
         }
    SaveDOC(saveFile);
    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
    }
    }//End Save selected layerSets along with background layer
if(win.g5.rb4.value){//Save all layerSets
    for(var g =0;g<LSets;g++){
         activeDocument.activeLayer = activeDocument.layerSets;
         var lName = activeDocument.activeLayer.name;
         var saveFile= File(outputFolder+ "/" + getName(g,lName));
    dupLayers();
        if(win.g12.cb1.value){
        try{activeDocument.mergeVisibleLayers();}catch(e){}
        }
    if(win.g12.cb2.value){
         try{activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true);}catch(e){}
         }
    SaveDOC(saveFile);
    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
        }
    }//End Save all layerSets
if(win.g5.rb5.value){//Save all layerSets along with the top layer
    activeDocument.activeLayer = activeDocument.layers[0];
    var TopIDX =getSelectedLayersIdx();
     for(var g =0;g<LSets;g++){
         activeDocument.activeLayer = activeDocument.layerSets;
         var lName = activeDocument.activeLayer.name;
         selectLayerByIndex(Number(TopIDX[0]),true);
         var saveFile= File(outputFolder+ "/" + getName(g,lName));
    dupLayers();
        if(win.g12.cb1.value){
        try{activeDocument.mergeVisibleLayers();}catch(e){}
        }
    if(win.g12.cb2.value){
         try{activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true);}catch(e){}
         }
    SaveDOC(saveFile);
    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
        }
    }//End Save all layerSets along with the top layer
if(win.g5.rb6.value){//Save all layerSets along with background layer
         for(var g =0;g<LSets;g++){
         activeDocument.activeLayer = activeDocument.layerSets;
         var lName = activeDocument.activeLayer.name;
         selectLayerByIndex(0,true);
         var saveFile= File(outputFolder+ "/" + getName(g,lName));
    dupLayers();
        if(win.g12.cb1.value){
        try{activeDocument.mergeVisibleLayers();}catch(e){}
        }
    if(win.g12.cb2.value){
         try{activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true);}catch(e){}
         }
    SaveDOC(saveFile);
    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
        }
    }//End Save all layerSets along with background layer
        }
}
function getName(seq,lName){
seq = zeroPad((Number(seq)+1), 3);
var dName = decodeURI(activeDocument.name).replace(/\.[^\.]+$/, '');
var Name ='';
switch (Number(win.g15.dd1.selection.index)){
    case 0: Name += lName; break;
    case 1: Name += dName +"-"+seq; break;
    case 2: Name += dName +"-"+ lName; break;
    case 3: Name += win.g15.et1.text + "-"+seq; break;
    default :break;
    }
return Name;
    }
function SaveDOC(saveFile){
    switch(Number(win.g18.dd1.selection.index)){
        case 0 : SavePNG(File(saveFile+".png")); break;
        case 1:  SavePSD(File(saveFile+".psd")); break;
        case 2:  SavePDF(File(saveFile+".pdf")); break;
        case 3:  SaveTIFF(File(saveFile+".tif")); break;
        case 3:  SaveJPG(File(saveFile+".jpg"),8); break;
        default : break;
        }
    }
}
main();
function hasBackground() {
   var ref = new ActionReference();
   ref.putProperty( charIDToTypeID("Prpr"), charIDToTypeID( "Bckg" ));
   ref.putEnumerated(charIDToTypeID( "Lyr " ),charIDToTypeID( "Ordn" ),charIDToTypeID( "Back" ));
   var desc =  executeActionGet(ref);
   var res = desc.getBoolean(charIDToTypeID( "Bckg" ));
   return res   
}
function getSelectedLayersIdx(){
      var selectedLayers = new Array;
      var ref = new ActionReference();
      ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
      var desc = executeActionGet(ref);
      if( desc.hasKey( stringIDToTypeID( 'targetLayers' ) ) ){
         desc = desc.getList( stringIDToTypeID( 'targetLayers' ));
          var c = desc.count
          var selectedLayers = new Array();
          for(var i=0;i<c;i++){
            try{
               activeDocument.backgroundLayer;
               selectedLayers.push(  desc.getReference( i ).getIndex() );
            }catch(e){
               selectedLayers.push(  desc.getReference( i ).getIndex()+1 );
            }
          }
       }else{
         var ref = new ActionReference();
         ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID( "ItmI" ));
         ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
         try{
            activeDocument.backgroundLayer;
            selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ))-1);
         }catch(e){
            selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" )));
         }
      }
      return selectedLayers;
};
function isLayerSet(idx) {        
   var ref = new ActionReference();
   ref.putIndex(1283027488, idx);
   var desc =  executeActionGet(ref);
   var type = desc.getEnumerationValue(stringIDToTypeID("layerSection"));
   var res = typeIDToStringID(type);
   if(res == 'layerSectionStart') return true;
       return false;  
}
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 selectLayerByIndex(index,add){
add = (add == undefined)  ? add = false : add;
var ref = new ActionReference();
    ref.putIndex(charIDToTypeID("Lyr "), index);
    var desc = new ActionDescriptor();
    desc.putReference(charIDToTypeID("null"), ref );
       if(add) desc.putEnumerated( stringIDToTypeID( "selectionModifier" ), stringIDToTypeID( "selectionModifierType" ), stringIDToTypeID( "addToSelection" ) );
      desc.putBoolean( charIDToTypeID( "MkVs" ), false );
   try{
    executeAction(charIDToTypeID("slct"), desc, DialogModes.NO );
}catch(e){}
};
function selectAllLayers(layer) {//does not select background layer
if(layer == undefined) layer = 0;
activeDocument.activeLayer = activeDocument.layers[activeDocument.layers.length-1];
if(activeDocument.activeLayer.isBackgroundLayer)
activeDocument.activeLayer = activeDocument.layers[activeDocument.layers.length-2];
var BL = activeDocument.activeLayer.name;
activeDocument.activeLayer = activeDocument.layers[layer];
    var desc5 = new ActionDescriptor();
        var ref3 = new ActionReference();
        ref3.putName( charIDToTypeID('Lyr '), BL);
    desc5.putReference( charIDToTypeID('null'), ref3 );
    desc5.putEnumerated( stringIDToTypeID('selectionModifier'), stringIDToTypeID('selectionModifierType'), stringIDToTypeID('addToSelectionContinuous') );
    desc5.putBoolean( charIDToTypeID('MkVs'), false );
    executeAction( charIDToTypeID('slct'), desc5, DialogModes.NO );
};
function zeroPad(n, s) {
   n = n.toString();
   while (n.length < s)  n = '0' + n;
   return n;
}
function SavePNG(saveFile){
    pngSaveOptions = new PNGSaveOptions();
activeDocument.saveAs(saveFile, pngSaveOptions, true, Extension.LOWERCASE);
}
function SaveTIFF(saveFile){
tiffSaveOptions = new TiffSaveOptions();
tiffSaveOptions.embedColorProfile = true;
tiffSaveOptions.alphaChannels = true;
tiffSaveOptions.layers = true;
tiffSaveOptions.imageCompression = TIFFEncoding.TIFFLZW;
activeDocument.saveAs(saveFile, tiffSaveOptions, true, Extension.LOWERCASE);
}
function SavePSD(saveFile){
psdSaveOptions = new PhotoshopSaveOptions();
psdSaveOptions.embedColorProfile = true;
psdSaveOptions.alphaChannels = true; 
activeDocument.saveAs(saveFile, psdSaveOptions, true, Extension.LOWERCASE);
}
function SavePDF(saveFile){
pdfSaveOptions = new PDFSaveOptions();
activeDocument.saveAs(saveFile, pdfSaveOptions, true, Extension.LOWERCASE);
}
function SaveJPG(saveFile, jpegQuality){
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);
}

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
New Here ,
May 19, 2011

Copy link to clipboard

Copied

Thank you! I'll tinker with this. Very nice interface. Kudos! Do you still want that beer money? Send me your Paypal email...

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Valorous Hero ,
May 19, 2011

Copy link to clipboard

Copied

Everything is free here, enjoy!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Engaged ,
Jul 01, 2011

Copy link to clipboard

Copied

very nice and helpful script!   thanks

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
New Here ,
Jul 20, 2011

Copy link to clipboard

Copied

Paul, this script is GREAT, and has nearly everything I need. Very nice indeed. I'm just getting exposed to scripting and hope to dive in myself soo.

That said, I have a few things happening that I would greatly appreciate help with...

In Paul's above script (which I have not modified), the 'save to jpg' function is buggy for me. Once I choose my settings and destination folder and activate the script, the output JPG files are 'blackholing.' They are just not ending up anywhere. PNG works fine.

I wonder if anyone might take a look at this with me?

Beyond getting JPG outp[ut to work, I can see one modification that would really make this script that much more powerful: Being able to include top and/or bottom LAYERSETS, instead of just layers. How involved is that kind of mod?

But really, the script is great and quite powerful. I just need the JPG output to work iin the near term.

Help, anyone?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
New Here ,
Jul 20, 2011

Copy link to clipboard

Copied

Just to be clear, the script I'm referring to is Paul's from May 19, 2011 5:18 PM.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Valorous Hero ,
Jul 20, 2011

Copy link to clipboard

Copied

Sorry about saving as jpg not working, I have now fixed that error and the new file can be downloaded from:-

http://www.scriptsrus.talktalk.net/

I will also have a look at adding the extra options as you have described.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
New Here ,
Jul 20, 2011

Copy link to clipboard

Copied

That is simply marvelous.

The saving of top and bottom groups would be quite helpful when it comes to baking in a flexible variety of fades and backgrounds into output images.

Very cool of you, and many thanks.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Valorous Hero ,
Jul 20, 2011

Copy link to clipboard

Copied

I have just added those options and is ready to be downloaded.

All the best.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
New Here ,
Jul 22, 2011

Copy link to clipboard

Copied

Paul, that is great, great stuff.

I know I'm likely teetering on the edge of asking for one too many favors, but something that would be quite useful is the addition of an option to:

Save all layerSets along with the top and bottom layerSets

That way, users could bake in a top effect, say, a fade or the like, along with a background.

Possible?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Valorous Hero ,
Jul 23, 2011

Copy link to clipboard

Copied

No Problem, it's done and ready to download

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Explorer ,
Aug 22, 2016

Copy link to clipboard

Copied

Hi Paul,

But in the above script save to .jpg format is not working in interface i don't know why and also i want my background layer and top layer also to be visible in all group jpegs

#target photoshop 

function main(){ 

var LSets = activeDocument.layerSets.length; 

var ArtLayers = activeDocument.artLayers.length; 

var NoOfLayers = activeDocument.layers.length; 

var Back = hasBackground(); 

var hasTop = false; 

var selLayers =getSelectedLayersIdx(); 

var selGroups=[]; 

if(LSets>0){ 

    for(var s in selLayers){ 

   if(isLayerSet(selLayers)) selGroups.push(selLayers); 

        } 

    } 

if(activeDocument.layers[0].typename == 'ArtLayer') hasTop = true; 

var win = new Window('dialog','Layer Saver'); 

g = win.graphics; 

var myBrush = g.newBrush(g.BrushType.SOLID_COLOR, [0.99, 0.99, 0.99, 1]); 

g.backgroundColor = myBrush; 

win.p1= win.add("panel", undefined, undefined, {borderStyle:"black"});  

win.p1.preferredSize=[500,20]; 

win.g1 = win.p1.add('group'); 

win.g1.orientation = "row"; 

win.title = win.g1.add('statictext',undefined,'Layer Saver'); 

win.title.alignment="fill"; 

var g = win.title.graphics; 

g.font = ScriptUI.newFont("Georgia","BOLDITALIC",22); 

win.g5 =win.p1.add('group'); 

win.g5.orientation = "column"; 

win.g5.alignChildren='left'; 

win.g5.spacing=0; 

if(LSets == 0){ 

win.g5.rb1 = win.g5.add('radiobutton',undefined,'Save selected layers'); 

win.g5.rb2 = win.g5.add('radiobutton',undefined,'Save selected layers along with the top layer'); 

win.g5.rb3 = win.g5.add('radiobutton',undefined,'Save selected layers along with background layer'); 

win.g5.rb4 = win.g5.add('radiobutton',undefined,'Save all layers'); 

win.g5.rb5 = win.g5.add('radiobutton',undefined,'Save all layers along with the top layer'); 

win.g5.rb6 = win.g5.add('radiobutton',undefined,'Save all layers along with background layer'); 

win.g5.rb3.enabled=Back; 

win.g5.rb6.enabled=Back; 

win.g5.rb4.value=true; 

}else{ 

win.g5.rb1 = win.g5.add('radiobutton',undefined,'Save selected layerSets'); 

win.g5.rb2 = win.g5.add('radiobutton',undefined,'Save selected layerSets along with the top layer'); 

win.g5.rb3 = win.g5.add('radiobutton',undefined,'Save selected layerSets along with background layer'); 

win.g5.rb4 = win.g5.add('radiobutton',undefined,'Save all layerSets'); 

win.g5.rb5 = win.g5.add('radiobutton',undefined,'Save all layerSets along with the top layer'); 

win.g5.rb6 = win.g5.add('radiobutton',undefined,'Save all layerSets along with background layer'); 

win.g5.rb3.enabled=Back; 

win.g5.rb6.enabled=Back; 

win.g5.rb2.enabled=hasTop; 

win.g5.rb5.enabled=hasTop; 

if(selGroups.length <1){ 

    win.g5.rb1.enabled=false; 

    win.g5.rb2.enabled=false; 

    win.g5.rb3.enabled=false; 

    } 

win.g5.rb4.value=true; 

    } 

win.p2 = win.add("panel", undefined, undefined, {borderStyle:"black"}); 

win.p2.preferredSize=[500,20]; 

win.p2.st1 = win.p2.add('statictext',undefined,'Output details'); 

win.p2.st1.graphics.font = ScriptUI.newFont("Tahoma", "Bold", 18); 

win.g10 =win.p2.add('group'); 

win.g10.orientation = "row"; 

win.g10.alignment='left'; 

win.g10.et1 = win.g10.add('edittext'); 

win.g10.et1.preferredSize=[350,20]; 

win.g10.bu1 = win.g10.add('button',undefined,'Select Folder'); 

win.g10.bu1.onClick=function(){ 

var Folder1 = Folder(app.activeDocument.path); 

outputFolder = Folder.selectDialog("Please select the output folder",Folder1);  

if(outputFolder !=null){ 

  win.g10.et1.text =  decodeURI(outputFolder.fsName);  

  } 

win.g12 =win.p2.add('group'); 

win.g12.orientation = "row"; 

win.g12.alignment='left'; 

win.g12.cb1 = win.g12.add('checkbox',undefined,'Merge Visible Layers?'); 

win.g12.cb2 = win.g12.add('checkbox',undefined,'Trim Layer'); 

win.g15 =win.p2.add('group'); 

win.g15.orientation = "row"; 

win.g15.alignment='left'; 

var Options= ["Layer/Group Name","FileName + Sequence No.","FileName + Layer/Group Name ","User Defined with Sequence No."]; 

win.g15.st1 = win.g15.add('statictext',undefined,'Save Options..'); 

win.g15.dd1 = win.g15.add('dropdownlist',undefined,Options); 

win.g15.dd1.selection=0; 

win.g15.et1 = win.g15.add('edittext'); 

win.g15.et1.preferredSize=[150,20]; 

win.g15.et1.hide(); 

win.g15.dd1.onChange=function(){ 

  if(this.selection.index==3){ 

      win.g15.et1.show(); 

      }else{ 

          win.g15.et1.hide(); 

          } 

    } 

win.g18 =win.p2.add('group'); 

win.g18.orientation = "row"; 

win.g18.st1 = win.g18.add('statictext',undefined,'Save as :'); 

var Types = ["PNG","PSD","PDF","TIF","JPG"]; 

win.g18.dd1 = win.g18.add('dropdownlist',undefined,Types); 

win.g18.dd1.selection = 0; 

win.g18.alignment='left'; 

win.g20 =win.p2.add('group'); 

win.g20.orientation = "row"; 

win.g20.bu1 = win.g20.add('button',undefined,'Process'); 

win.g20.bu1.preferredSize=[200,35]; 

win.g20.bu2 = win.g20.add('button',undefined,'Cancel'); 

win.g20.bu2.preferredSize=[200,35]; 

win.g20.bu1.onClick=function(){ 

    if(win.g10.et1.text == ''){ 

        alert("No Output Folder has been Selected!"); 

        return; 

        } 

    if(win.g15.dd1.selection.index==3){ 

        if(win.g15.et1.text ==''){ 

            alert("No FileName Has Been Entered!"); 

            return; 

            } 

        } 

    win.close(1); 

Process(); 

win.center(); 

win.show(); 

function Process(){ 

if(LSets == 0){ 

//Process layers only 

if(win.g5.rb1.value){//Save selected layers 

for(var b in selLayers){ 

    selectLayerByIndex(Number(selLayers)); 

     var lName = activeDocument.activeLayer.name; 

    var saveFile= File(outputFolder+ "/" + getName(b,lName)); 

    dupLayers(); 

    if(win.g12.cb1.value){ 

        try{activeDocument.mergeVisibleLayers();}catch(e){} 

        } 

     if(win.g12.cb2.value){ 

         try{activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true);}catch(e){} 

         } 

    SaveDOC(saveFile); 

    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES); 

    } 

    }//End Save selected layers 

if(win.g5.rb2.value){//Save selected layers along with the top layer 

for(var b in selLayers){ 

    selectLayerByIndex(Number(selLayers)); 

     var lName = activeDocument.activeLayer.name; 

    activeDocument.activeLayer= activeDocument.layers[0]; 

    selectLayerByIndex(Number(selLayers),true); 

    var saveFile= File(outputFolder+ "/" + getName(b,lName)); 

    dupLayers(); 

    if(win.g12.cb1.value){ 

        try{activeDocument.mergeVisibleLayers();}catch(e){} 

        } 

    if(win.g12.cb2.value){ 

         try{activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true);}catch(e){} 

         } 

    SaveDOC(saveFile); 

    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES); 

    } 

    }//End Save selected layers along with the top layer 

if(win.g5.rb3.value){//Save selected layers along with background layer 

    for(var b in selLayers){ 

    selectLayerByIndex(Number(selLayers)); 

     var lName = activeDocument.activeLayer.name; 

    activeDocument.activeLayer = activeDocument.layers[activeDocument.layers.length-1]; 

    selectLayerByIndex(Number(selLayers),true); 

    var saveFile= File(outputFolder+ "/" + getName(b,lName)); 

    dupLayers(); 

        if(win.g12.cb1.value){ 

        try{activeDocument.mergeVisibleLayers();}catch(e){} 

        } 

    if(win.g12.cb2.value){ 

         try{activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true);}catch(e){} 

         } 

    SaveDOC(saveFile); 

    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES); 

    } 

    }//End Save selected layers along with background layer 

if(win.g5.rb4.value){//Save all layers 

selectAllLayers(); 

selLayers =getSelectedLayersIdx(); 

for(var b in selLayers){ 

     selectLayerByIndex(Number(selLayers)); 

     var lName = activeDocument.activeLayer.name; 

    var saveFile= File(outputFolder+ "/" + getName(b,lName)); 

    dupLayers(); 

        if(win.g12.cb1.value){ 

        try{activeDocument.mergeVisibleLayers();}catch(e){} 

        } 

    if(win.g12.cb2.value){ 

         try{activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true);}catch(e){} 

         } 

    SaveDOC(saveFile); 

    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES); 

     } 

    }//End Save all layers 

if(win.g5.rb5.value){//Save all layers along with the top layer 

selectAllLayers(1); 

selLayers =getSelectedLayersIdx(); 

for(var b in selLayers){ 

    selectLayerByIndex(Number(selLayers)); 

     var lName = activeDocument.activeLayer.name; 

    activeDocument.activeLayer = activeDocument.layers[0]; 

    selectLayerByIndex(Number(selLayers),true); 

    var saveFile= File(outputFolder+ "/" + getName(b,lName)); 

    dupLayers(); 

        if(win.g12.cb1.value){ 

        try{activeDocument.mergeVisibleLayers();}catch(e){} 

        } 

    if(win.g12.cb2.value){ 

         try{activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true);}catch(e){} 

         } 

    SaveDOC(saveFile); 

    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES); 

    } 

    }//End Save all layers along with the top layer 

if(win.g5.rb6.value){//Save all layers along with background layer 

selectAllLayers(); 

selLayers =getSelectedLayersIdx(); 

    for(var b in selLayers){ 

    selectLayerByIndex(Number(selLayers)); 

     var lName = activeDocument.activeLayer.name; 

    activeDocument.activeLayer = activeDocument.layers[activeDocument.layers.length-1]; 

    selectLayerByIndex(Number(selLayers),true); 

    var saveFile= File(outputFolder+ "/" + getName(b,lName)); 

    dupLayers(); 

        if(win.g12.cb1.value){ 

        try{activeDocument.mergeVisibleLayers();}catch(e){} 

        } 

    if(win.g12.cb2.value){ 

         try{activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true);}catch(e){} 

         } 

    SaveDOC(saveFile); 

    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES); 

    } 

    }//End Save all layers along with background layer 

    }else{ 

//Process LayerSets Only 

if(win.g5.rb1.value){//Save selected layerSets 

    for(var g in selGroups){ 

        selectLayerByIndex(Number(selGroups)); 

        var lName = activeDocument.activeLayer.name; 

        var saveFile= File(outputFolder+ "/" + getName(g,lName)); 

        dupLayers(); 

            if(win.g12.cb1.value){ 

        try{activeDocument.mergeVisibleLayers();}catch(e){} 

        } 

    if(win.g12.cb2.value){ 

         try{activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true);}catch(e){} 

         } 

    SaveDOC(saveFile); 

    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES); 

        } 

   }//End Save selected layerSets 

if(win.g5.rb2.value){//Save selected layerSets along with the top layer 

    for(var g in selGroups){ 

        selectLayerByIndex(Number(selGroups)); 

     var lName = activeDocument.activeLayer.name; 

    activeDocument.activeLayer= activeDocument.layers[0]; 

    selectLayerByIndex(Number(selGroups),true); 

    var saveFile= File(outputFolder+ "/" + getName(g,lName)); 

    dupLayers(); 

        if(win.g12.cb1.value){ 

        try{activeDocument.mergeVisibleLayers();}catch(e){} 

        } 

    if(win.g12.cb2.value){ 

         try{activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true);}catch(e){} 

         } 

    SaveDOC(saveFile); 

    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES); 

        } 

    }//End Save selected layerSets along with the top layer 

if(win.g5.rb3.value){//Save selected layerSets along with background layer 

    for(var g in selGroups){ 

    selectLayerByIndex(Number(selGroups)); 

     var lName = activeDocument.activeLayer.name; 

    activeDocument.activeLayer = activeDocument.layers[activeDocument.layers.length-1]; 

    selectLayerByIndex(Number(selGroups),true); 

    var saveFile= File(outputFolder+ "/" + getName(g,lName)); 

    dupLayers(); 

        if(win.g12.cb1.value){ 

        try{activeDocument.mergeVisibleLayers();}catch(e){} 

        } 

    if(win.g12.cb2.value){ 

         try{activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true);}catch(e){} 

         } 

    SaveDOC(saveFile); 

    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES); 

    } 

    }//End Save selected layerSets along with background layer 

if(win.g5.rb4.value){//Save all layerSets 

    for(var g =0;g<LSets;g++){ 

         activeDocument.activeLayer = activeDocument.layerSets

         var lName = activeDocument.activeLayer.name; 

         var saveFile= File(outputFolder+ "/" + getName(g,lName)); 

    dupLayers(); 

        if(win.g12.cb1.value){ 

        try{activeDocument.mergeVisibleLayers();}catch(e){} 

        } 

    if(win.g12.cb2.value){ 

         try{activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true);}catch(e){} 

         } 

    SaveDOC(saveFile); 

    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES); 

        } 

    }//End Save all layerSets 

if(win.g5.rb5.value){//Save all layerSets along with the top layer 

    activeDocument.activeLayer = activeDocument.layers[0]; 

    var TopIDX =getSelectedLayersIdx(); 

     for(var g =0;g<LSets;g++){ 

         activeDocument.activeLayer = activeDocument.layerSets

         var lName = activeDocument.activeLayer.name; 

         selectLayerByIndex(Number(TopIDX[0]),true); 

         var saveFile= File(outputFolder+ "/" + getName(g,lName)); 

    dupLayers(); 

        if(win.g12.cb1.value){ 

        try{activeDocument.mergeVisibleLayers();}catch(e){} 

        } 

    if(win.g12.cb2.value){ 

         try{activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true);}catch(e){} 

         } 

    SaveDOC(saveFile); 

    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES); 

        } 

    }//End Save all layerSets along with the top layer 

if(win.g5.rb6.value){//Save all layerSets along with background layer 

         for(var g =0;g<LSets;g++){ 

         activeDocument.activeLayer = activeDocument.layerSets

         var lName = activeDocument.activeLayer.name; 

         selectLayerByIndex(0,true); 

         var saveFile= File(outputFolder+ "/" + getName(g,lName)); 

    dupLayers(); 

        if(win.g12.cb1.value){ 

        try{activeDocument.mergeVisibleLayers();}catch(e){} 

        } 

    if(win.g12.cb2.value){ 

         try{activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true);}catch(e){} 

         } 

    SaveDOC(saveFile); 

    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES); 

        } 

    }//End Save all layerSets along with background layer 

        } 

function getName(seq,lName){ 

seq = zeroPad((Number(seq)+1), 3); 

var dName = decodeURI(activeDocument.name).replace(/\.[^\.]+$/, ''); 

var Name =''; 

switch (Number(win.g15.dd1.selection.index)){ 

    case 0: Name += lName; break; 

    case 1: Name += dName +"-"+seq; break; 

    case 2: Name += dName +"-"+ lName; break; 

    case 3: Name += win.g15.et1.text + "-"+seq; break; 

    default :break; 

    } 

return Name; 

    } 

function SaveDOC(saveFile){ 

    switch(Number(win.g18.dd1.selection.index)){ 

        case 0 : SavePNG(File(saveFile+".png")); break; 

        case 1:  SavePSD(File(saveFile+".psd")); break; 

        case 2:  SavePDF(File(saveFile+".pdf")); break; 

        case 3:  SaveTIFF(File(saveFile+".tif")); break; 

        case 3:  SaveJPG(File(saveFile+".jpg"),8); break; 

        default : break; 

        } 

    } 

main(); 

function hasBackground() {  

   var ref = new ActionReference();  

   ref.putProperty( charIDToTypeID("Prpr"), charIDToTypeID( "Bckg" ));  

   ref.putEnumerated(charIDToTypeID( "Lyr " ),charIDToTypeID( "Ordn" ),charIDToTypeID( "Back" )); 

   var desc =  executeActionGet(ref);  

   var res = desc.getBoolean(charIDToTypeID( "Bckg" ));  

   return res     

}  

function getSelectedLayersIdx(){  

      var selectedLayers = new Array;  

      var ref = new ActionReference();  

      ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );  

      var desc = executeActionGet(ref);  

      if( desc.hasKey( stringIDToTypeID( 'targetLayers' ) ) ){  

         desc = desc.getList( stringIDToTypeID( 'targetLayers' ));  

          var c = desc.count  

          var selectedLayers = new Array();  

          for(var i=0;i<c;i++){  

            try{  

               activeDocument.backgroundLayer;  

               selectedLayers.push(  desc.getReference( i ).getIndex() );  

            }catch(e){  

               selectedLayers.push(  desc.getReference( i ).getIndex()+1 );  

            }  

          }  

       }else{  

         var ref = new ActionReference();  

         ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID( "ItmI" ));  

         ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );  

         try{  

            activeDocument.backgroundLayer;  

            selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ))-1);  

         }catch(e){  

            selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" )));  

         }  

      }  

      return selectedLayers;  

}; 

function isLayerSet(idx) {          

   var ref = new ActionReference();  

   ref.putIndex(1283027488, idx);  

   var desc =  executeActionGet(ref);  

   var type = desc.getEnumerationValue(stringIDToTypeID("layerSection"));  

   var res = typeIDToStringID(type);  

   if(res == 'layerSectionStart') return true; 

       return false;    

}  

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 selectLayerByIndex(index,add){  

add = (add == undefined)  ? add = false : add; 

var ref = new ActionReference(); 

    ref.putIndex(charIDToTypeID("Lyr "), index); 

    var desc = new ActionDescriptor(); 

    desc.putReference(charIDToTypeID("null"), ref ); 

       if(add) desc.putEnumerated( stringIDToTypeID( "selectionModifier" ), stringIDToTypeID( "selectionModifierType" ), stringIDToTypeID( "addToSelection" ) );  

      desc.putBoolean( charIDToTypeID( "MkVs" ), false );  

   try{ 

    executeAction(charIDToTypeID("slct"), desc, DialogModes.NO ); 

}catch(e){} 

}; 

function selectAllLayers(layer) {//does not select background layer 

if(layer == undefined) layer = 0; 

activeDocument.activeLayer = activeDocument.layers[activeDocument.layers.length-1]; 

if(activeDocument.activeLayer.isBackgroundLayer)  

activeDocument.activeLayer = activeDocument.layers[activeDocument.layers.length-2]; 

var BL = activeDocument.activeLayer.name; 

activeDocument.activeLayer = activeDocument.layers[layer]; 

    var desc5 = new ActionDescriptor(); 

        var ref3 = new ActionReference(); 

        ref3.putName( charIDToTypeID('Lyr '), BL); 

    desc5.putReference( charIDToTypeID('null'), ref3 ); 

    desc5.putEnumerated( stringIDToTypeID('selectionModifier'), stringIDToTypeID('selectionModifierType'), stringIDToTypeID('addToSelectionContinuous') ); 

    desc5.putBoolean( charIDToTypeID('MkVs'), false ); 

    executeAction( charIDToTypeID('slct'), desc5, DialogModes.NO ); 

}; 

function zeroPad(n, s) {  

   n = n.toString();  

   while (n.length < s)  n = '0' + n;  

   return n;  

function SavePNG(saveFile){ 

    pngSaveOptions = new PNGSaveOptions();  

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

function SaveTIFF(saveFile){ 

tiffSaveOptions = new TiffSaveOptions();  

tiffSaveOptions.embedColorProfile = true;  

tiffSaveOptions.alphaChannels = true;  

tiffSaveOptions.layers = true; 

tiffSaveOptions.imageCompression = TIFFEncoding.TIFFLZW;  

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

function SavePSD(saveFile){  

psdSaveOptions = new PhotoshopSaveOptions();  

psdSaveOptions.embedColorProfile = true;  

psdSaveOptions.alphaChannels = true;   

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

function SavePDF(saveFile){  

pdfSaveOptions = new PDFSaveOptions();  

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

function SaveJPG(saveFile, jpegQuality){ 

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); 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Explorer ,
Nov 26, 2018

Copy link to clipboard

Copied

I found in the 2019CC test that I couldn't export jpg, what's going on?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
LEGEND ,
Dec 04, 2018

Copy link to clipboard

Copied

You may have to provide more information to enable anybody to provide pertinent advice.

Which exact Script did you use, what is the active file’s Layer structure, …?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
New Here ,
Sep 01, 2011

Copy link to clipboard

Copied

Its not working on mac cs5

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
New Here ,
Dec 21, 2011

Copy link to clipboard

Copied

After 30 mins on Google I found this thread and downloaded the script for Layer Saver

I knew what I wanted to do, but not how to do it.

I have 100s of files each with up to 100 layers that I need to export as separate trimmed psd files

This script does it. It has saved me so much hassle and so a HUGE 'thank you' is due to you

and of course,

Seasons Greetings !

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
New Here ,
Feb 06, 2012

Copy link to clipboard

Copied

sounds great,but

is this script also available for Illustrator?

That would make our day and make you the person of the year!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
LEGEND ,
Feb 06, 2012

Copy link to clipboard

Copied

is this script also available for Illustrator?

Say what?

Photoshop and Illustrator’s Document Object Models are quite different, so a Script’s functionality is not necessarily (easily) transferable.

Anyway, you might want to check over at

http://forums.adobe.com/community/illustrator/illustrator_scripting

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
New Here ,
Feb 06, 2012

Copy link to clipboard

Copied

I know, but it would be awesome if such a great script also is available for Illustrator.

Will have a look at your link, thanks pfaffenbichler

if somebody has found it please post it here

keep up the good work y'all

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...