Highlighted

Layer Saver script no longer works in photoshop cc 2017

New Here ,
Oct 30, 2017

Copy link to clipboard

Copied

Absolutely gutted, nothing ever made in Photoshop ever came close to it and i have been using it for years

I know there is one in PS and another on GITHUB but nothing comes close to the original script

The things that set it apart was the fact that you could save layers with Prefixes and increment the files with hyphens and numbers such as MFOTL395 and it would merge visible and/or selected layers in to files and name them MFOTL395-01.jpg, MFOTL395-02.jpg and so on

You could also set it to save selected layers along with the top or bottom most layers, including smart objects and backgrounds

Please someone update this script so it works in PS CC 2017, i have it safe if anyone has the talent to do this, it works in CS6 and I think it works in CC 2015

I create t-shirt designs and have all the 13 colours of shirt at the bottom of my file and all the smart vector objects above, i can select all 13 blank coloured t-shirts and merge each one with a selected smart vector object and create all the colour variation images or ebay, amazon, my website etc in seconds for each design

OH GOD, OH NO

Paul Riggott script, correct? He shared them "as is", but he didn't provide support for the latest versions of Photoshop as far as I know.

Which one you're interested in, Layer Saver or Layer Saver Plus? What kind of error does it pop?

You can always use PS CS6, it's still available from the CC app downloads.

Davide

Topics

Actions and scripting

Views

1.7K

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

Layer Saver script no longer works in photoshop cc 2017

New Here ,
Oct 30, 2017

Copy link to clipboard

Copied

Absolutely gutted, nothing ever made in Photoshop ever came close to it and i have been using it for years

I know there is one in PS and another on GITHUB but nothing comes close to the original script

The things that set it apart was the fact that you could save layers with Prefixes and increment the files with hyphens and numbers such as MFOTL395 and it would merge visible and/or selected layers in to files and name them MFOTL395-01.jpg, MFOTL395-02.jpg and so on

You could also set it to save selected layers along with the top or bottom most layers, including smart objects and backgrounds

Please someone update this script so it works in PS CC 2017, i have it safe if anyone has the talent to do this, it works in CS6 and I think it works in CC 2015

I create t-shirt designs and have all the 13 colours of shirt at the bottom of my file and all the smart vector objects above, i can select all 13 blank coloured t-shirts and merge each one with a selected smart vector object and create all the colour variation images or ebay, amazon, my website etc in seconds for each design

OH GOD, OH NO

Paul Riggott script, correct? He shared them "as is", but he didn't provide support for the latest versions of Photoshop as far as I know.

Which one you're interested in, Layer Saver or Layer Saver Plus? What kind of error does it pop?

You can always use PS CS6, it's still available from the CC app downloads.

Davide

Topics

Actions and scripting

Views

1.8K

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 ,
Oct 30, 2017

Copy link to clipboard

Copied

here is what it looks like in cs6

Capture5.PNG

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 ,
Oct 30, 2017

Copy link to clipboard

Copied

Paul Riggott script, correct? He shared them "as is", but he didn't provide support for the latest versions of Photoshop as far as I know.

Which one you're interested in, Layer Saver or Layer Saver Plus? What kind of error does it pop?

You can always use PS CS6, it's still available from the CC app downloads.

Davide

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 ,
Oct 30, 2017

Copy link to clipboard

Copied

I didnt know there was a layer saver plus version just always used it the normal version

I have noticed that the domain that hosted loads of free scripts has how disappeared which is a shame and i would be prepared to host the scripts if i could find the original hoster

yes i have a version of CS6 but I am worried that sooner or later it will not be available anymore

Its a real shame its not being worked on anymore-

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 ,
Oct 30, 2017

Copy link to clipboard

Copied

thanks for the info, i found the github and had a look at the layer saver plus but could get it to do anything

Nice to know its on github, maybe someone might get it working with later versions of PS

Thanks for your help

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 ,
Oct 30, 2017

Copy link to clipboard

Copied

What happens to you when launching the Layer Saver? Mine shows up (well, the background is white whereas some text has its own background, but the window itself seems working) I've not tested it on actual files though.

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 ,
Oct 30, 2017

Copy link to clipboard

Copied

Yes exact same, cant make out the options or text, but i suppose it might work

Maybe i can have a look at the script and see if i can adjust its contrast, ill have a look

Cheers

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 ,
Oct 30, 2017

Copy link to clipboard

Copied

Just read the sad news that the owner of photoshop-scripts.com passed away

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...
Advocate ,
Oct 31, 2017

Copy link to clipboard

Copied

Simply change this line:

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

to

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

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 ,
Oct 31, 2017

Copy link to clipboard

Copied

Cheers i will give it ago

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 ,
Oct 31, 2017

Copy link to clipboard

Copied

I have a similar script.. is this the same one? And by the way, it works on my CC2018 installation

#target Photoshop

app.bringToFront();

main();

function main(){

if(!documents.length) return;

Prefs ={};

var UUID = 'f1742f10-a6de-11e2-9e96-0800200c9a66';

try{

var desc1 = app.getCustomOptions(UUID);

Prefs = eval(desc1.getString(0));

}catch(e){

Prefs.Trim=false;

Prefs.Merge=false;

Prefs.OutFolder=app.activeDocument.path;

Prefs.SaveOptions=0;

Prefs.FileType=4;

Prefs.TiffOptions =0;

Prefs.Quality =79;

Prefs.jpgQuality=7;

}

var selLayers = getSelectedLayersIdx();

selectedLayers =new Array();

selectedLayers = getNormalLayers(selLayers);

var LayerSetLayers=[];

var lSets = getLayerSets();

for(var z in lSets){

var lset = getChildIndex(Number(lSets), true );

LayerSetLayers[Number(lSets)] = lset;

}

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

g = win.graphics;

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

g.backgroundColor = myBrush;

win.orientation='stack';

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

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

win.g1.orientation = "row";

win.title = win.g1.add('statictext',undefined,'LayerSet 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 = "row";

win.g5.alignment='fill';

win.g5.spacing=10;

win.g5.p1= win.g5.add("panel", undefined, 'Please Select LayerSets', {borderStyle:"black"});

win.g5.p1.preferredSize=[250,200];

win.g5.p1.lb1 = win.g5.p1.add('listbox', undefined, undefined, {multiselect: true} );

win.g5.p1.lb1.preferredSize=[220,170];

win.g5.p2= win.g5.add("panel", undefined, 'What to Do', {borderStyle:"black"});

win.g5.p2.preferredSize=[250,200];

for(var a in lSets){

    win.g5.p1.lb1.add('item',(getLayerNameByIndex( Number(lSets))));

}

win.g50 =win.g5.p2.add('group');

win.g50.orientation = "column";

win.g50.alignment='left';

win.g50.alignChildren='left';

win.g50.spacing=10;

win.g50.rb1 = win.g50.add('radiobutton',undefined,'Save selected layers ('+selectedLayers.length + ')?');

win.g50.rb2 = win.g50.add('radiobutton',undefined,'Save all layers in all LayerSets?');

win.g50.rb3 = win.g50.add('radiobutton',undefined,'Save all layers in selected LayerSets?');

win.g50.rb4 = win.g50.add('radiobutton',undefined,'Save selected LayerSets?');

win.g50.rb5 = win.g50.add('radiobutton',undefined,'Save all LayerSets?');

win.g50.rb1.value=true;

win.g50.rb1.onClick=function(){

    if(win.g50.rb1.value) {

        win.g5.p1.lb1.enabled=false;

        }else{

            win.g5.p1.lb1.enabled=true;

            }

    }

win.g50.rb1.onClick();

win.g50.rb2.onClick=function(){

    win.g50.rb1.onClick();

    }

win.g50.rb3.onClick=function(){

    win.g50.rb1.onClick();

    }

win.g50.rb4.onClick=function(){

    win.g50.rb1.onClick();

    }

win.g50.rb5.onClick=function(){

    win.g50.rb1.onClick();

    }

var lSetsSelected=new Array();

for(var f in lSets){

    for(var t in selLayers){

        if(Number(lSets) == Number(selLayers)){

            lSetsSelected.push(f);

            }

        }

    }

if(lSetsSelected.length > 0){

    win.g5.p1.lb1.selection = lSetsSelected;

    win.g50.rb4.value=true;

    win.g50.rb1.onClick();

    }

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

win.g100.alignment='row';

win.g100.spacing=10;

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

win.g100.p1.preferredSize=[520,40];

win.g100a =win.g100.p1.add('group');

win.g100a.alignment='fill';

win.g100a.spacing=10;

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

win.g100a.et1.preferredSize=[390,20];

win.g100a.et1.enabled=false;

//win.g100a.bu1 = win.g100a.add( 'image', undefined, 'SourceFolderIcon' );

win.g100a.bu1 = win.g100a.add( 'button', undefined, 'Browse' );

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

try{

    docPath = Prefs.OutFolder;

    }catch(e){docPath= Folder("~");}

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

if(outputFolder !=null){

        Prefs.OutFolder=outputFolder;

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

}

}

if(Folder(Prefs.OutFolder).exists){

    outputFolder=Folder(Prefs.OutFolder);

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

    }

win.g100b =win.g100.p1.add('group');

win.g100b.alignment='fill';

win.g100b.spacing=10;

win.g100b.cb1 = win.g100b.add('checkbox',undefined,'Merge visible Layers?');

win.g100b.cb2 = win.g100b.add('checkbox',undefined,'Trim Layer(s)?');

win.g100b.cb2.value = Prefs.Trim;

win.g100b.cb1.value = Prefs.Merge;

win.g120 =win.g100.p1.add('group');

win.g120.orientation = "row";

win.g120.alignment='left';

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

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

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

win.g120.dd1.selection=Number(Prefs.SaveOptions);

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

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

win.g120.et1.hide();

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

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

      win.g120.et1.show();

      }else{

          win.g120.et1.hide();

          }

    }

win.g125 =win.g100.p1.add('group');

win.g125.orientation = "row";

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

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

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

win.g125.dd1.selection = Number(Prefs.FileType);

win.g125.alignment='left';

win.g130 =win.g125.add('group');

win.g130.orientation = "stack";

win.g130b =win.g130.add('group');

win.g130b.st1 = win.g130b.add('statictext',undefined,'Quality');

win.g130b.dd1 = win.g130b.add('dropdownlist');

for(var a =1;a<13;a++){

    win.g130b.dd1.add('item',a);

    }

win.g130b.dd1.selection = Number(Prefs.jpgQuality);

win.g130b.visible=false;

win.g130c =win.g130.add('group');

win.g130c.st1 = win.g130c.add('statictext',undefined,'Compression');

var tiffOptions=["LZW","ZIP","JPG","None"];

win.g130c.dd1 = win.g130c.add('dropdownlist',undefined,tiffOptions);

win.g130c.dd1.selection = Prefs.TiffOptions;

win.g130c.visible=false;

win.g130d =win.g130.add('group');

win.g130d.st1 = win.g130d.add('statictext',undefined,'Quality');

win.g130d.dd1 = win.g130d.add('dropdownlist');

for(var a =1;a<101;a++){

    win.g130d.dd1.add('item',a);

    }

win.g130d.dd1.selection=Prefs.Quality;

win.g130d.visible=false;

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

    switch(Number(this.selection.index)){

        case 0 : win.g130b.visible=false; win.g130c.visible=false; win.g130d.visible=false; break;

        case 1 : win.g130b.visible=false; win.g130c.visible=false; win.g130d.visible=false; break;

        case 2 : win.g130b.visible=false; win.g130c.visible=false; win.g130d.visible=false; break;

        case 3 : win.g130b.visible=false; win.g130c.visible=true; win.g130d.visible=false; break;

        case 4 : win.g130b.visible=true; win.g130c.visible=false; win.g130d.visible=false; break;

        case 5 : win.g130b.visible=false; win.g130c.visible=false; win.g130d.visible=true; break;

        default :break;

        }

}

win.g125.dd1.onChange();

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

win.g1000.alignment='row';

win.g1000.spacing=10;

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

win.g1000.p1.preferredSize=[520,40];

win.g1000.p1.orientation = "row";

win.g1000.p1.alignment='fill';

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

win.g1000.p1.bu1.preferredSize=[235,30];

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

win.g1000.p1.bu2.preferredSize=[235,30];

function SaveDOC(saveFile){

    switch(Number(win.g125.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"),Number(win.g130c.dd1.selection.index)); break;

        case 4:  SaveJPG(File(saveFile+".jpg"),Number(win.g130b.dd1.selection.index)+1); break;

        case 5:  SaveForWeb(File(saveFile+".jpg"),Number(win.g130d.dd1.selection.index)+1)  break;

        default : break;

        }

};

function getName(seq,lName){

lName = lName.replace(/\....$/,'');

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

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

var Name ='';

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

    case 0: Name += lName; break;

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

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

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

    default :break;

    }

return Name;

}

  

win.g1000.p1.bu1.onClick=function(){

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

    alert("No output folder has been selected!");

    return;

        }

if(!outputFolder.exists){

    alert("Output folder does not exist!");

    return;

    }

Prefs.Merge = win.g100b.cb1.value;

Prefs.Trim = win.g100b.cb2.value;

Prefs.SaveOptions=win.g120.dd1.selection.index;

Prefs.FileType = win.g125.dd1.selection.index;

Prefs.TiffOptions = win.g130c.dd1.selection.index;

Prefs.Quality = win.g130d.dd1.selection.index;

Prefs.jpgQuality=win.g130b.dd1.selection.index;

var desc2 = new ActionDescriptor();

desc2.putString(0, Prefs.toSource());

app.putCustomOptions(UUID, desc2, true );

win.close(0);

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

for(var a in selectedLayers){

var lName = getLayerNameByIndex( Number(selectedLayers)).toString().replace(/[:\/\\*\?\"\<\>\|]/g, "_");

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

selectLayerByIndex(Number(selectedLayers));

dupLayers();

if(win.g100b.value)  try{activeDocument.mergeVisibleLayers();}catch(e){}

if(win.g100b.cb2.value){

try{

activeDocument.backgroundLayer;

var back = true;

}catch(e){var back =false;}

    if(!back){

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

        }else{

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

            }

    }

SaveDOC(saveFile);

app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

    }//end selected layers

    };

if(win.g50.rb2.value){//Save all layers in all LayerSets

var count =0;

for(var a in lSets){

    var layerToProcess = LayerSetLayers[Number(lSets)];

    var selectedLay = getNormalLayers(layerToProcess);

for(var b in selectedLay){

var lName = getLayerNameByIndex( Number(selectedLay)).toString().replace(/[:\/\\*\?\"\<\>\|]/g, "_");

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

selectLayerByIndex(Number(selectedLay));

dupLayers();

if(win.g100b.value)  try{activeDocument.mergeVisibleLayers();}catch(e){}

if(win.g100b.cb2.value){

try{

activeDocument.backgroundLayer;

var back = true;

}catch(e){var back =false;}

    if(!back){

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

        }else{

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

            }

    }

SaveDOC(saveFile);

app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

count++;

    }//end selectedlay

    }

    };//end Save all layers in all LayerSets

if(win.g50.rb3.value){//Save all layers in selected LayerSets

var lSets2 = new Array();

var selGroups = win.g5.p1.lb1.selection;

for(var g in  selGroups){ lSets2.push(Number(lSets[Number(selGroups)]));}

var count =0;

for(var a in lSets2){

    var layerToProcess = LayerSetLayers[Number(lSets2)];

    var selectedLay = getNormalLayers(layerToProcess);

for(var b in selectedLay){

var lName = getLayerNameByIndex( Number(selectedLay)).toString().replace(/[:\/\\*\?\"\<\>\|]/g, "_");

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

selectLayerByIndex(Number(selectedLay));

dupLayers();

if(win.g100b.value)  try{activeDocument.mergeVisibleLayers();}catch(e){}

if(win.g100b.cb2.value){

try{

activeDocument.backgroundLayer;

var back = true;

}catch(e){var back =false;}

    if(!back){

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

        }else{

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

            }

    }

SaveDOC(saveFile);

app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

count++;

    }//end selectedlay

    }

    };//end Save all layers in selected LayerSets

if(win.g50.rb4.value){//Save selected LayerSets

var lSets2 = new Array();

var selGroups = win.g5.p1.lb1.selection;

for(var g in  selGroups){ lSets2.push(Number(lSets[Number(selGroups.index)]));}

var count =0;

for(var a in lSets2){

var lName = getLayerNameByIndex( Number(lSets2)).toString().replace(/[:\/\\*\?\"\<\>\|]/g, "_");

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

selectLayerByIndex(Number(lSets2));

dupLayers();

if(win.g100b.value)  try{activeDocument.mergeVisibleLayers();}catch(e){}

if(win.g100b.cb2.value){

try{

activeDocument.backgroundLayer;

var back = true;

}catch(e){var back =false;}

    if(!back){

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

        }else{

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

            }

    }

SaveDOC(saveFile);

app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

count++;

    }//end lSets2

    };//end Save  selected LayerSets

if(win.g50.rb5.value){//Save all LayerSets

var count =0;

for(var a in lSets){

var lName = getLayerNameByIndex( Number(lSets)).toString().replace(/[:\/\\*\?\"\<\>\|]/g, "_");

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

selectLayerByIndex(Number(lSets));

dupLayers();

if(win.g100b.value)  try{activeDocument.mergeVisibleLayers();}catch(e){}

if(win.g100b.cb2.value){

try{

activeDocument.backgroundLayer;

var back = true;

}catch(e){var back =false;}

    if(!back){

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

        }else{

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

            }

    }

SaveDOC(saveFile);

app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

count++;

    }//end lSets

    };//end Save all LayerSets

};

win.show();

};

//Functions

function isLayerSet(idx){

var ref = new ActionReference();

ref.putProperty( charIDToTypeID("Prpr") , stringIDToTypeID( 'layerSection' ));

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

var desc = executeActionGet(ref);

var isSet = typeIDToStringID(desc.getEnumerationValue(stringIDToTypeID('layerSection')));

var LayerSet=false;

switch (isSet.toString()){

    case 'layerSectionStart' : LayerSet=true; break;

    case 'layerSectionEnd' : LayerSet=true; break;

    case 'layerSectionConent' : LayerSet=false; break;

    }

return LayerSet;

};

function selectLayerByIndex(index,add,vis){

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

    if (vis == undefined) vis = false;

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" ), vis );

  try{

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

}catch(e){}

};

function noOfLayers(){

   var ref = new ActionReference();

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

   return executeActionGet(ref).getInteger(charIDToTypeID('NmbL'));

}

function getLayerSets(){

   var ref = new ActionReference();

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

   var count = executeActionGet(ref).getInteger(charIDToTypeID('NmbL')) +1;

   var Lsets=[];

try{

    activeDocument.backgroundLayer;

var i = 0; }catch(e){ var i = 1; };

   for(i;i<count;i++){

       if(i == 0) continue;

        ref = new ActionReference();

        ref.putIndex( charIDToTypeID( 'Lyr ' ), i );

        var desc = executeActionGet(ref);

        var layerName = desc.getString(charIDToTypeID( 'Nm  ' ));

        if(layerName.match(/^<\/Layer group/) ) continue;

        var layerType = typeIDToStringID(desc.getEnumerationValue( stringIDToTypeID( 'layerSection' )));

        var isLayerSet =( layerType == 'layerSectionContent') ? false:true;

        if(isLayerSet) Lsets.push(i);

   };

return Lsets;

};

function getLayerLayerSectionByIndex( index ) {  

   var ref = new ActionReference();

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

   return typeIDToStringID(executeActionGet(ref).getEnumerationValue(stringIDToTypeID('layerSection')));

};

function getLayerNameByIndex( index ) {

    var ref = new ActionReference();

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

    return executeActionGet(ref).getString(charIDToTypeID( 'Nm  ' ));

};

function skipNestedSets( layerIndex ){

   var isEnd = false;

   layerIndex = app.activeDocument.layers[app.activeDocument.layers.length-1].isBackgroundLayer ? layerIndex-2:layerIndex;

   while(!isEnd){

      layerIndex--;

      if( getLayerLayerSectionByIndex( layerIndex ) == 'layerSectionStart' ) layerIndex = skipNestedSets( layerIndex );

      isEnd = getLayerNameByIndex(layerIndex) == '</Layer group>' ? true:false;

   }

   return layerIndex-1;

};

function getChildIndex(idx, skipNested ){

   var layerSetIndex = idx;

   var isEndOfSet = false;

   var layerIndexArray = [];

   while(!isEndOfSet){

      layerSetIndex--;

      if( getLayerLayerSectionByIndex( layerSetIndex ) == 'layerSectionStart' && skipNested ){

         layerSetIndex = skipNestedSets( layerSetIndex );

      }

  if(getLayerLayerSectionByIndex( layerSetIndex ) == undefined) break;

      isEndOfSet = getLayerNameByIndex(layerSetIndex) == '</Layer group>' ? true:false;

     if(!isEndOfSet ) layerIndexArray.push( layerSetIndex );

   }

   return layerIndexArray;

};

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 getIDXs(){

   var ref = new ActionReference();

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

   var count = executeActionGet(ref).getInteger(charIDToTypeID('NmbL')) +1;

   var IDX=[];

try{

    activeDocument.backgroundLayer;

var i = 0; }catch(e){ var i = 1; };

   for(i;i<count;i++){

       if(i == 0) continue;

        ref = new ActionReference();

        ref.putIndex( charIDToTypeID( 'Lyr ' ), i );

        var desc = executeActionGet(ref);

        var layerName = desc.getString(charIDToTypeID( 'Nm  ' ));

        var Id = desc.getInteger(stringIDToTypeID( 'layerID' ));

        if(layerName.match(/^<\/Layer group/) ) continue;

        var layerType = typeIDToStringID(desc.getEnumerationValue( stringIDToTypeID( 'layerSection' )));

        var isLayerSet =( layerType == 'layerSectionContent') ? false:true;

        if(!isLayerSet) IDX.push(i);

   };

return IDX;

};

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

         }

     var vis = app.activeDocument.activeLayer.visible;

        if(vis == true) app.activeDocument.activeLayer.visible = false;

        var desc9 = new ActionDescriptor();

    var list9 = new ActionList();

    var ref9 = new ActionReference();

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

    list9.putReference( ref9 );

    desc9.putList( charIDToTypeID('null'), list9 );

    executeAction( charIDToTypeID('Shw '), desc9, DialogModes.NO );

    if(app.activeDocument.activeLayer.visible == false) selectedLayers.shift();

        app.activeDocument.activeLayer.visible = vis;

      }

      return selectedLayers;

};

function dupLayers() {

var desc = new ActionDescriptor();

var ref = new ActionReference();

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

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

desc.putString( charIDToTypeID('Nm  '), "Dup" );

var ref2 = new ActionReference();

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

desc.putReference( charIDToTypeID('Usng'), ref2 );

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

};

function getLayerKindByIndex( index ) {

    var ref, desc, adjustmentDesc, layerSectionType;

   ref = new ActionReference();

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

   desc =  executeActionGet(ref);

   if( desc.hasKey( stringIDToTypeID( 'textKey' ) ) ) return LayerKind.TEXT;

   if( desc.hasKey( stringIDToTypeID( 'smartObject' ) ) ) return LayerKind.SMARTOBJECT;// includes LayerKind.VIDEO

   if( desc.hasKey( stringIDToTypeID( 'layer3D' ) ) ) return LayerKind.LAYER3D;

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

      switch(typeIDToStringID(desc.getList (stringIDToTypeID('adjustment')).getClass (0))){

      case 'photoFilter' : return LayerKind.PHOTOFILTER;

      case 'solidColorLayer' : return LayerKind.SOLIDFILL;

      case 'gradientMapClass' : return LayerKind.GRADIENTMAP;

      case 'gradientMapLayer' : return LayerKind.GRADIENTFILL;

      case 'hueSaturation' : return LayerKind.HUESATURATION;

      case 'colorLookup' : return undefined; //this does not exist and errors with getting layer kind

      case 'colorBalance' : return LayerKind.COLORBALANCE;

      case 'patternLayer' : return LayerKind.PATTERNFILL;

      case 'invert' : return LayerKind.INVERSION;

      case 'posterization' : return LayerKind.POSTERIZE;

      case 'thresholdClassEvent' : return LayerKind.THRESHOLD;

      case 'blackAndWhite' : return LayerKind.BLACKANDWHITE;

      case 'selectiveColor' : return LayerKind.SELECTIVECOLOR;

      case 'vibrance' : return LayerKind.VIBRANCE;

      case 'brightnessEvent' : return LayerKind.BRIGHTNESSCONTRAST;

      case  'channelMixer' : return LayerKind.CHANNELMIXER;

      case 'curves' : return LayerKind.CURVES;

      case 'exposure' : return LayerKind.EXPOSURE;

      // if not one of the above adjustments return - adjustment layer type

      default : return typeIDToStringID(desc.getList (stringIDToTypeID('adjustment')).getClass (0));

      }

   }

var layerType = typeIDToStringID(desc.getEnumerationValue( stringIDToTypeID( 'layerSection' )));

return ( layerType == 'layerSectionContent') ? LayerKind.NORMAL:undefined;

};

function getNormalLayers(array){

var selectedLayers = new Array();

for(var t in array){ 

   switch(getLayerKindByIndex( Number(array)) ){

       case LayerKind.NORMAL :

       case  LayerKind.SMARTOBJECT :

       case LayerKind.SOLIDFILL :

       case LayerKind.TEXT : selectedLayers.push(Number(array)); break;

       default : break;

       }

    }

return selectedLayers;

}

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,Comp){

tiffSaveOptions = new TiffSaveOptions();

tiffSaveOptions.embedColorProfile = true;

tiffSaveOptions.transparency = true;

tiffSaveOptions.alphaChannels = true;

tiffSaveOptions.layers = true;

switch (Number(Comp)){

    case 0 : tiffSaveOptions.imageCompression = TIFFEncoding.TIFFLZW; break;

    case 1 : tiffSaveOptions.imageCompression = TIFFEncoding.TIFFZIP; break;

    case 2 : tiffSaveOptions.imageCompression = TIFFEncoding.JPEG; break;

    case 3 : tiffSaveOptions.imageCompression = TIFFEncoding.NONE; break;

    default : break;

}

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

};

function SavePSD(saveFile){

psdSaveOptions = new PhotoshopSaveOptions();

psdSaveOptions.embedColorProfile = true;

psdSaveOptions.alphaChannels = true; 

psdSaveOptions.layers = 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){

    try{

jpgSaveOptions = new JPEGSaveOptions();

jpgSaveOptions.embedColorProfile = true;

jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;

jpgSaveOptions.matte = MatteType.NONE;

jpgSaveOptions.quality = jpegQuality;

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

}catch(e){$.writeln(e+" - "+e.line);}

};

function SaveForWeb(saveFile,jpegQuality) {

var tmpFile=File(saveFile.path +"/tmpName.jpg");

var sfwOptions = new ExportOptionsSaveForWeb();

   sfwOptions.format = SaveDocumentType.JPEG;

   sfwOptions.includeProfile = false;

   sfwOptions.interlaced = 0;

   sfwOptions.optimized = true;

   sfwOptions.quality = Number(jpegQuality);

activeDocument.exportDocument(tmpFile, ExportType.SAVEFORWEB, sfwOptions);

tmpFile.rename(decodeURI(saveFile.name));

};

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 ,
Oct 31, 2017

Copy link to clipboard

Copied

No its not this one has 1350 lines

#target photoshop

function main(){

if(!documents.length) return;

if(activeDocument.layers.length == 1) return;

var Prefs ={};

try{

  var desc1 = app.getCustomOptions('ed0f5560-dfb3-11e0-9572-0800200c9a66');

  Prefs = eval(desc1.getString(0));

    }catch(e){

Prefs={

saveType:0,

tiffComp:0,

jpgQual:11,

jpgsfwQual:79,

FileName:0,

merge:false,

trim:false,

rUnits:0,

rMethod:0,

Folder1:decodeURI(app.activeDocument.path)

};

}

var doc = activeDocument;

var LSets = activeDocument.layerSets.length;

var LSetsVis=[];

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

//Photoshop CS6 or CC has a bug in the font size, so it won't fit on a laptop screen so use row.

if(app.version.match(/\d+/) >= 13 && $.screens[0].bottom < 800 ){

win.orientation = "row";

}

g = win.graphics;

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

g.backgroundColor = myBrush;

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

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

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.rb7 = win.g5.add('radiobutton',undefined,'Save all layers along with bottom layer');

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

win.g5.rb9 = win.g5.add('radiobutton',undefined,'Save selected layers along with top and background layers');

win.g5.rb3.enabled=Back;

win.g5.rb6.enabled=Back;

win.g5.rb7.enabled=!Back;

win.g5.rb8.enabled=!Back;

win.g5.rb9.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.rb7 = win.g5.add('radiobutton',undefined,'Save all layerSets along with top layerset');

win.g5.rb8 = win.g5.add('radiobutton',undefined,'Save all layerSets along with bottom layerset');

win.g5.rb9 = win.g5.add('radiobutton',undefined,'Save all layerSets along with top and bottom layersets');

win.g5.rb10 = win.g5.add('radiobutton',undefined,'Save all layers within all layerSets');

win.g5.rb4a = win.g5.add('checkbox',undefined,'Save all layerSets along with selected layers');

win.g5.rb4a.helpTip="No LayerSets should be selected!\rOnly layers to be saved with each LayerSet";

win.g5.rb3.enabled=Back;

win.g5.rb6.enabled=Back;

win.g5.rb2.enabled=hasTop;

win.g5.rb5.enabled=hasTop;

if(LSets < 3){

    win.g5.rb7.enabled=false;

    win.g5.rb8.enabled=false;

    }

if(LSets < 4){

    win.g5.rb9.enabled=false;

    }

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,260];

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.et1.enabled=false;

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

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

Folder1 = Folder(Prefs.Folder1);

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

if(outputFolder !=null){

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

}

}

if(Folder(Prefs.Folder1).exists){

    outputFolder= Folder(Prefs.Folder1);

    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.cb1.value = Prefs.merge;

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

win.g12.cb2.value=Prefs.trim;

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

win.g11.spacing=10;

win.g11.orientation = 'row';

win.g11.alignment="left";

win.g11.cb1 = win.g11.add('checkbox',undefined,'Run Action');

win.g11.dd1 = win.g11.add('dropdownlist');

win.g11.dd1.preferredSize=[150,20];

win.g11.dd2 = win.g11.add('dropdownlist');

win.g11.dd2.preferredSize=[150,20];

win.g11.dd1.enabled=false;

win.g11.dd2.enabled=false;

win.g11.cb1.onClick = function(){

    if(win.g11.cb1.value){

        win.g11.dd1.enabled=true;

        win.g11.dd2.enabled=true;  

        }else{

            win.g11.dd1.enabled=false;

            win.g11.dd2.enabled=false;

            }

}

var actions = new Array();

var actionSets= new Array();

actionSets = getActionSets();

for (var i=0,len=actionSets.length;i<len;i++) {

win.g11.dd1.add ('item', "" + actionSets); 

};

win.g11.dd1.selection=0;

actions = getActions(actionSets[0]);

for (var i=0,len=actions.length;i<len;i++) {

win.g11.dd2.add ('item', "" + actions);   

};

win.g11.dd2.selection=0;

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

win.g11.dd2.removeAll();

actions = getActions(actionSets[parseInt(this.selection)]);

for (var i=0,len=actions.length;i<len;i++) {

win.g11.dd2.add ('item', "" + actions); 

}

win.g11.dd2.selection=0;

};

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

win.g14.orientation = "row";

win.g14.alignment='left';

win.g14.cb1 = win.g14.add('checkbox',undefined,'Add Suffix/Prefix');

win.g14.rb1 = win.g14.add('radiobutton',undefined,'Prefix');

win.g14.rb2 = win.g14.add('radiobutton',undefined,'Suffix');

win.g14.rb2.value=true;

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.","Group Name + LayerName"];

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

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

win.g15.dd1.remove(4);

if(Number(Prefs.FileName) == 4) Prefs.FileName = 0;

win.g15.dd1.selection=Number(Prefs.FileName);

if(LSets > 0){

win.g5.rb1.onClick=function(){

    win.g5.rb4a.value=false;

        win.g5.rb4a.enabled=false;

    win.g5.rb10.onClick();

    }

win.g5.rb2.onClick=function(){

    win.g5.rb4a.value=false;

        win.g5.rb4a.enabled=false;

    win.g5.rb10.onClick();

    }

win.g5.rb2.onClick=function(){

    win.g5.rb4a.value=false;

        win.g5.rb4a.enabled=false;

    win.g5.rb10.onClick();

    }

win.g5.rb3.onClick=function(){

    win.g5.rb4a.value=false;

        win.g5.rb4a.enabled=false;

    win.g5.rb10.onClick();

    }

win.g5.rb4.onClick=function(){

    if(win.g5.rb4.value){

    win.g5.rb4a.enabled=true;

    }

    win.g5.rb10.onClick();

    }

win.g5.rb5.onClick=function(){

   win.g5.rb4a.value=false;

        win.g5.rb4a.enabled=false;

    win.g5.rb10.onClick();

    }

win.g5.rb6.onClick=function(){

    win.g5.rb4a.value=false;

        win.g5.rb4a.enabled=false;

    win.g5.rb10.onClick();

    }

win.g5.rb7.onClick=function(){

    win.g5.rb4a.value=false;

        win.g5.rb4a.enabled=false;

    win.g5.rb10.onClick();

    }

win.g5.rb8.onClick=function(){

    win.g5.rb4a.value=false;

        win.g5.rb4a.enabled=false;

    win.g5.rb10.onClick();

    }

win.g5.rb9.onClick=function(){

    win.g5.rb4a.value=false;

        win.g5.rb4a.enabled=false;

    win.g5.rb10.onClick();

    }

win.g15.dd1.add('item','Group Name + LayerName');

win.g5.rb10.onClick=function(){

    if(win.g5.rb4.value){

    win.g5.rb4a.enabled=true;

    }else{

   win.g5.rb4a.value=false;

        win.g5.rb4a.enabled=false;

        }

    if(win.g5.rb10.value){

        win.g15.dd1.add('item','Group Name + LayerName');

        }else{

            try{

            win.g15.dd1.remove(4);

            }catch(e){}

            win.g15.dd1.selection=0;

            }

}

win.g5.rb4.onClick();

}

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==0){

      win.g14.cb1.enabled=true;

      }else{

          win.g14.cb1.value=false;

          win.g14.cb1.enabled=false;

          }

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

      win.g15.et1.show();

      }else{

          win.g15.et1.hide();

          }

    }

win.g14.cb1.onClick=function(){

    if(win.g14.cb1.value){

        win.g15.et1.show();

        }else{

            win.g15.et1.hide();

            }

    }

win.g15.dd1.onChange();

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","JPG SFW","PCX","PNG SFW"];

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

win.g18.dd1.selection = Number(Prefs.saveType);

win.g18.alignment='left';

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

win.g19.orientation = "stack";

win.g19b =win.g19.add('group');

win.g19b.st1 = win.g19b.add('statictext',undefined,'Quality');

win.g19b.dd1 = win.g19b.add('dropdownlist');

for(var a =1;a<13;a++){

    win.g19b.dd1.add('item',a);

    }

win.g19b.dd1.selection = Number(Prefs.jpgQual);

win.g19b.visible=false;

win.g19c =win.g19.add('group');

win.g19c.st1 = win.g19c.add('statictext',undefined,'Compression');

var tiffOptions=["LZW","ZIP","JPG","None"];

win.g19c.dd1 = win.g19c.add('dropdownlist',undefined,tiffOptions);

win.g19c.dd1.selection = Number(Prefs.tiffComp);

win.g19c.visible=false;

win.g19d =win.g19.add('group');

win.g19d.st1 = win.g19d.add('statictext',undefined,'Quality');

win.g19d.dd1 = win.g19d.add('dropdownlist');

for(var a =1;a<101;a++){

    win.g19d.dd1.add('item',a);

    }

win.g19d.dd1.selection = Number(Prefs.jpgsfwQual);

win.g19d.visible=false;

win.g19d.cb1 = win.g19d.add('checkbox',undefined,'Nearest Size Kilobytes');

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

win.g19d.cb1.helpTip="This could take some time as multiple saves are required!";

win.g19d.et1.preferredSize=[70,20];

win.g19d.cb1.onClick = function(){

    if(win.g19d.cb1.value){

        win.g19d.dd1.enabled=false;

        win.g19d.et1.enabled=true;

        }else{

            win.g19d.dd1.enabled=true;

            win.g19d.et1.enabled=false;

            }

}

win.g19d.et1.onChanging = function() {

  if (this.text.match(/[^\-\.\d]/)) {

    this.text = this.text.replace(/[^\-\.\d]/g, '');

  }

};

win.g19d.cb1.onClick();

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

    switch(Number(this.selection.index)){

        case 0 : win.g19b.visible=false; win.g19c.visible=false; win.g19d.visible=false; break;

        case 1 : win.g19b.visible=false; win.g19c.visible=false; win.g19d.visible=false; break;

        case 2 : win.g19b.visible=false; win.g19c.visible=false; win.g19d.visible=false; break;

        case 3 : win.g19b.visible=false; win.g19c.visible=true; win.g19d.visible=false; break;

        case 4 : win.g19b.visible=true; win.g19c.visible=false; win.g19d.visible=false; break;

        case 5 : win.g19b.visible=false; win.g19c.visible=false; win.g19d.visible=true; break;

        case 6 : win.g19b.visible=false; win.g19c.visible=false; win.g19d.visible=false; break;

        case 7 : win.g19b.visible=false; win.g19c.visible=false; win.g19d.visible=false; break;

        default :break;

        }

}

win.g18.dd1.onChange();

////*******************************************************

try{

resizeMethod = ["Bicubic", "BicubicSharper","BicubicSmoother", "Bilinear", "NearestNeighbor"];

resizeUnits = ["pixels", "percent", "inches","cm", "mm", "points", "picas"];

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

win.g29a.spacing=0;

win.g29a.orientation = 'row';

win.g29a.alignment="left";

win.g29a.cb0 = win.g29a.add('checkbox',undefined,'Custom Fit Image');

win.g29a.cb1 = win.g29a.add('checkbox',undefined,'Constrain Proportions');

win.g29a.cb1.value=true;

win.g29a.cb1.helpTip="If unticked this could distort the image!";

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

win.g29b.spacing=0;

win.g29b.orientation = 'row';

win.g29b.alignment="left";

win.g29b.st1 = win.g29b.add('statictext',undefined,'Width');

win.g29b.et1 = win.g29b.add('edittext',undefined,'');

win.g29b.et1.preferredSize=[40,20];

win.g29b.st2 = win.g29b.add('statictext',undefined,'Height');

win.g29b.et2 = win.g29b.add('edittext',undefined,'');

win.g29b.et2.preferredSize=[40,20];

win.g29b.dd1 = win.g29b.add('dropdownlist',undefined,resizeUnits);

win.g29b.dd1.selection= Prefs.rUnits;

win.g29b.dd2 = win.g29b.add('dropdownlist',undefined,resizeMethod);

win.g29b.dd2.selection= Prefs.rMethod;

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

win.g29c.spacing=0;

win.g29c.orientation = 'row';

win.g29c.alignment="left";

win.g29c.cb0 = win.g29c.add('checkbox',undefined,'Use document resolution');

win.g29c.cb0.value=true;

win.g29c.st1 = win.g29c.add('statictext',undefined,'Enter resolution');

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

win.g29c.et1.preferredSize=[40,20];

win.g29c.et1.onChanging = function() {

  if (this.text.match(/[^\-\.\d]/)) {

    this.text = this.text.replace(/[^\-\.\d]/g, '');

  }

};

win.g29c.cb0.onClick=function(){

    if(win.g29c.cb0.value){

        win.g29c.et1.visible=false;

        win.g29c.st1.visible=false;

        }else{

            win.g29c.et1.visible=true;

            win.g29c.st1.visible=true;

            }

    }

win.g29c.cb0.onClick();

win.g29a.cb0.onClick = function(){

    if(win.g29a.cb0.value){

        win.g29a.cb1.enabled=true;

        win.g29b.et1.enabled=true;

        win.g29b.et2.enabled=true;

        win.g29b.dd1.enabled=true;

        win.g29b.dd2.enabled=true;

        win.g29c.cb0.enabled=true;

        }else{

            win.g29a.cb1.enabled=false;

            win.g29b.et1.enabled=false;

            win.g29b.et2.enabled=false;

            win.g29b.dd1.enabled=false;

            win.g29b.dd2.enabled=false;

            win.g29c.cb0.enabled=false;

            win.g29c.cb0.value=true;

            win.g29c.cb0.onClick();

            win.g29a.cb1.value=true;

            }

}

win.g29b.et1.onChanging = function() {

  if (this.text.match(/[^\-\.\d]/)) {

    this.text = this.text.replace(/[^\-\.\d]/g, '');

  }

};

win.g29b.et2.onChanging = function() {

  if (this.text.match(/[^\-\.\d]/)) {

    this.text = this.text.replace(/[^\-\.\d]/g, '');

  }

};

win.g29a.cb0.onClick();

}catch(e){alert(e+" - "+e.line);}

////*******************************************************

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

win.g200.orientation = "row";

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

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

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

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

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

    if(win.g19d.cb1.value){

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

            alert("No JPG size has been entered!");

            return;

            }

        }

    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;

            }

        }

    if(win.g14.cb1.value){

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

            alert("No Prefix/Suffix Has Been Entered!");

            return;

            }

        }

    if(win.g29a.cb0.value){//Resize output file

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

            alert("No Width has been entered for the resize!");

            return;

            }

        if(win.g29b.et2.text == ''){

            alert("No Height has been entered for the resize!");

            return;

            }

        if(!win.g29c.cb0.value && win.g29c.et1.text == ''){

            alert("No resolution has been entered!");

            return;

            }

        }

Prefs.jpgsfwQual = win.g19d.dd1.selection.index;

Prefs.tiffComp = win.g19c.dd1.selection.index;

Prefs.jpgQual = win.g19b.dd1.selection.index

Prefs.saveType = win.g18.dd1.selection.index;

Prefs.FileName = win.g15.dd1.selection.index;

Prefs.merge = win.g12.cb1.value;

Prefs.trim = win.g12.cb2.value;

Prefs.rUnits = win.g29b.dd1.selection.index;

Prefs.rMethod = win.g29b.dd2.selection.index;

Prefs.Folder1= decodeURI(outputFolder); 

var desc2 = new ActionDescriptor();

desc2.putString(0, Prefs.toSource());

app.putCustomOptions('ed0f5560-dfb3-11e0-9572-0800200c9a66', desc2, true );

win.close(1);

if($.os.match(/windows/gi)){

if(app.version.match(/\d+/) ==13){

var Tabbed = isTabInterface();

if(!Tabbed) tabInterface();

}

}

Process();

if($.os.match(/windows/gi)){

if(app.version.match(/\d+/) ==13){

if(!Tabbed) tabInterface(false);

}

}

}

win.center();

win.show();

function Process(){

function resizeDoc(){

//Custom Fit Image ****************************

var doc=activeDocument;

resUnits= win.g29b.dd1.selection.text.toString();

resWidth = new UnitValue(Number(win.g29b.et1.text),resUnits); 

resHeight = new UnitValue(Number(win.g29b.et2.text),resUnits);

if(win.g29a.cb1.value){//Constrain Proportions

  if(doc.width>doc.height){

      resHeight = undefined;

      }else{

          resWidth = undefined;

   }

}

if(!win.g29a.cb1.value){

    if(doc.height > doc.width){

        resHeight = new UnitValue(Number(win.g29b.et1.text),resUnits); 

        resWidth = new UnitValue(Number(win.g29b.et2.text),resUnits);

        }

}

if(win.g29c.cb0.value){

resizeRes = undefined;

}else{

    resizeRes = Math.round(Number(win.g29c.et1.text));

    }

resizeMethods = win.g29b.dd2.selection.text.toString().toUpperCase();

activeDocument.resizeImage (resWidth, resHeight, resizeRes, eval("ResampleMethod."+resizeMethods));

//end custom Fit Image

}

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){}

         }

     if(win.g11.cb1.value) doAction(win.g11.dd2.selection.text, win.g11.dd1.selection.text);

    if(win.g29a.cb0.value) resizeDoc();

    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){}

         }

     if(win.g11.cb1.value) doAction(win.g11.dd2.selection.text, win.g11.dd1.selection.text);

     if(win.g29a.cb0.value) resizeDoc();

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

    activeDocument.layers[0].visible=true;

        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){}

         }

     if(win.g11.cb1.value) doAction(win.g11.dd2.selection.text, win.g11.dd1.selection.text);

     if(win.g29a.cb0.value) resizeDoc();

    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){}

         }

     if(win.g11.cb1.value) doAction(win.g11.dd2.selection.text, win.g11.dd1.selection.text);

     if(win.g29a.cb0.value) resizeDoc();

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

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){}

         }

     if(win.g11.cb1.value) doAction(win.g11.dd2.selection.text, win.g11.dd1.selection.text);

     if(win.g29a.cb0.value) resizeDoc();

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

    activeDocument.layers[0].visible=true;

        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){}

         }

     if(win.g11.cb1.value) doAction(win.g11.dd2.selection.text, win.g11.dd1.selection.text);

     if(win.g29a.cb0.value) resizeDoc();

    SaveDOC(saveFile);

    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

    }

    }//End Save all layers along with background layer

if(win.g5.rb7.value){//Save all layers along with bottom layer

selectAllLayers();

selLayers =getSelectedLayersIdx();

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

var bottomLayer = getSelectedLayersIdx();

    for(var b in selLayers){

     if(Number(selLayers) == Number(bottomLayer[0])) continue;

    selectLayerByIndex(Number(selLayers));

     var lName = activeDocument.activeLayer.name;

    selectLayerByIndex(Number(bottomLayer[0]),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){}

         }

     if(win.g11.cb1.value) doAction(win.g11.dd2.selection.text, win.g11.dd1.selection.text);

     if(win.g29a.cb0.value) resizeDoc();

    SaveDOC(saveFile);

    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

    }

    }//End Save all layers along with bottom layer

if(win.g5.rb8.value){//Save selected layers along with bottom layer

selLayers =getSelectedLayersIdx();

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

var bottomLayer = getSelectedLayersIdx();

    for(var b in selLayers){

     if(Number(selLayers) == Number(bottomLayer[0])) continue;

    selectLayerByIndex(Number(selLayers));

     var lName = activeDocument.activeLayer.name;

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

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

    dupLayers();

    activeDocument.layers[0].visible=true;

        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){}

         }

     if(win.g11.cb1.value) doAction(win.g11.dd2.selection.text, win.g11.dd1.selection.text);

     if(win.g29a.cb0.value) resizeDoc();

    SaveDOC(saveFile);

    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

    }

    }//End Save selected layers along with bottom layer

if(win.g5.rb9.value){//Save selected layers along with top and bottom layer

selLayers =getSelectedLayersIdx();

activeDocument.activeLayer = activeDocument.layers[0];

var topLayer = getSelectedLayersIdx();

    for(var b in selLayers){

     if(Number(selLayers) == Number(topLayer[0])) continue;

    selectLayerByIndex(Number(selLayers));

     var lName = activeDocument.activeLayer.name;

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

    selectLayerByIndex(0,true);

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

    dupLayers();

    activeDocument.layers[0].visible=true;

        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){}

         }

     if(win.g11.cb1.value) doAction(win.g11.dd2.selection.text, win.g11.dd1.selection.text);

     if(win.g29a.cb0.value) resizeDoc();

    SaveDOC(saveFile);

    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

    }

    }//End Save selected layers along with top and bottom 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){}

         }

     if(win.g11.cb1.value) doAction(win.g11.dd2.selection.text, win.g11.dd1.selection.text);

     if(win.g29a.cb0.value) resizeDoc();

    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){}

         }

     if(win.g11.cb1.value) doAction(win.g11.dd2.selection.text, win.g11.dd1.selection.text);

     if(win.g29a.cb0.value) resizeDoc();

    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){}

         }

     if(win.g11.cb1.value) doAction(win.g11.dd2.selection.text, win.g11.dd1.selection.text);

     if(win.g29a.cb0.value) resizeDoc();

    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 y =0; y< LSets;y++){

    LSetsVis.push(doc.layerSets.visible);

    doc.layerSets.visible=false;

    }

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

         activeDocument.activeLayer = activeDocument.layerSets;

         var lName = activeDocument.activeLayer.name;

         activeDocument.layerSets.visible=true;

         if(win.g5.rb4a.value){

         for(var d in selLayers ){   

         selectLayerByIndex(Number(selLayers),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){}

         }

     if(win.g11.cb1.value) doAction(win.g11.dd2.selection.text, win.g11.dd1.selection.text);

     if(win.g29a.cb0.value) resizeDoc();

    SaveDOC(saveFile);

    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

    activeDocument.layerSets.visible=false;

        }

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

    doc.layerSets.visible = LSetsVis;

    }

         if(win.g5.rb4a.value){

         for(var d in selLayers ){   

         selectLayerByIndex(Number(selLayers),true);

         }

     }

    }//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){}

         }

     if(win.g11.cb1.value) doAction(win.g11.dd2.selection.text, win.g11.dd1.selection.text);

     if(win.g29a.cb0.value) resizeDoc();

    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){}

         }

     if(win.g11.cb1.value) doAction(win.g11.dd2.selection.text, win.g11.dd1.selection.text);

     if(win.g29a.cb0.value) resizeDoc();

    SaveDOC(saveFile);

    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

        }

    }//End Save all layerSets along with background layer

if(win.g5.rb7.value){//Save all layerSets along with top layerset

    activeDocument.activeLayer = activeDocument.layerSets[0];

   var topLayerSet = getSelectedLayersIdx();

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

         activeDocument.activeLayer = activeDocument.layerSets;

         var lName = activeDocument.activeLayer.name;

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

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

    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){}

         }

     if(win.g11.cb1.value) doAction(win.g11.dd2.selection.text, win.g11.dd1.selection.text);

     if(win.g29a.cb0.value) resizeDoc();

    SaveDOC(saveFile);

    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

        }

    }//End Save all layerSets along with top layerset

if(win.g5.rb8.value){//Save all layerSets along with bottom layerset

    activeDocument.activeLayer = activeDocument.layerSets[LSets-1];

   var bottomLayerSet = getSelectedLayersIdx();

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

         activeDocument.activeLayer = activeDocument.layerSets;

         var lName = activeDocument.activeLayer.name;

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

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

    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){}

         }

     if(win.g11.cb1.value) doAction(win.g11.dd2.selection.text, win.g11.dd1.selection.text);

     if(win.g29a.cb0.value) resizeDoc();

    SaveDOC(saveFile);

    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

        }

    }//End Save all layerSets along with bottom layerset

if(win.g5.rb9.value){//Save all layerSets along with top and bottom layerset

    activeDocument.activeLayer = activeDocument.layerSets[0];

   var topLayerSet = getSelectedLayersIdx();

    activeDocument.activeLayer = activeDocument.layerSets[LSets-1];

   var bottomLayerSet = getSelectedLayersIdx();

    for(var g =1;g<LSets-1;g++){

         activeDocument.activeLayer = activeDocument.layerSets;

         var lName = activeDocument.activeLayer.name;

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

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

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

    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){}

         }

     if(win.g11.cb1.value) doAction(win.g11.dd2.selection.text, win.g11.dd1.selection.text);

     if(win.g29a.cb0.value) resizeDoc();

    SaveDOC(saveFile);

    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

        }

    }//End Save all layerSets along with top and bottom layerset

if(win.g5.rb10.value){//Save all layers including those in layersets

selectAllLayers();

selLayers =getSelectedLayersIdx();

for(var b in selLayers){

     selectLayerByIndex(Number(selLayers));

     if(activeDocument.activeLayer.typename == 'LayerSet') continue;

     if(app.activeDocument.activeLayer.kind == LayerKind.HUESATURATION ) continue;

      if(app.activeDocument.activeLayer.kind == LayerKind.COLORBALANCE ) continue;

     if(app.activeDocument.activeLayer.kind ==  LayerKind.CURVES ) continue;

      if(app.activeDocument.activeLayer.kind == LayerKind.LEVELS ) continue;

      if(app.activeDocument.activeLayer.kind == LayerKind.BLACKANDWHITE ) continue;

      if(app.activeDocument.activeLayer.kind == LayerKind.BRIGHTNESSCONTRAST ) continue;

      if(app.activeDocument.activeLayer.kind == LayerKind.GRADIENTFILL ) continue;

      if(app.activeDocument.activeLayer.kind == LayerKind.GRADIENTMAP ) continue;

      if(app.activeDocument.activeLayer.kind == LayerKind.INVERSION ) continue;

      if(app.activeDocument.activeLayer.kind == LayerKind.GRADIENTFILL ) continue;

      if(app.activeDocument.activeLayer.kind == LayerKind.PATTERNFILL ) continue;

      if(app.activeDocument.activeLayer.kind == LayerKind.SELECTIVECOLOR ) continue;

      if(app.activeDocument.activeLayer.kind == LayerKind.THRESHOLD ) continue;    

     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){}

         }

     if(win.g11.cb1.value) doAction(win.g11.dd2.selection.text, win.g11.dd1.selection.text);

     if(win.g29a.cb0.value) resizeDoc();

    SaveDOC(saveFile);

    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

     }

    }//End Save all layers

        }

}

function getName(seq,lName){

lName = lName.replace(/\....$/,'');

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

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

var Name ='';

if(win.g15.dd1.selection.index ==0 && win.g14.cb1.value){

    if(win.g14.rb1.value){

        Name += win.g15.et1.text + lName;

        return Name;

        }else{

        Name += lName + win.g15.et1.text;

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

    case 4: Name += ParentName() + lName; break;

    default :break;

    }

return Name;

    }

function ParentName(){

if(activeDocument.activeLayer.parent.typename == "LayerSet") {

return activeDocument.activeLayer.parent.name + " - ";

}else{

    return "";

}

    }

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"),Number(win.g19c.dd1.selection.index)); break;

        case 4:  SaveJPG(File(saveFile+".jpg"),Number(win.g19b.dd1.selection.index)+1); break;

        case 5:  SFW(saveFile); break;

        case 6:  savePCX(saveFile +".pcx"); break;

        case 7: saveAsPNG24SFW(File(saveFile+".png")); break;

        default : break;

        }

    }

function SFW(saveFile){

  if(!win.g19d.cb1.value){

      SaveForWeb(File(saveFile+".jpg"),Number(win.g19d.dd1.selection.index)+1);

      }else{

          try{

          tmpFile = File(saveFile+".jpg");

          for(var z =100;z>5;z -=4){

              SaveForWeb(tmpFile,z);

              var chkFile = File(saveFile+".jpg");

              // $.writeln(tmpFile + " qual = " + z + " Size = " +(chkFile.length/1024).toFixed(2) + "k" );

              if((chkFile.length/1024).toFixed(2) < Number(win.g19d.et1.text)) break;

              tmpFile.remove();

              }

          if(!tmpFile.exists)  SaveForWeb(tmpFile,5);

          }catch(e){$.writeln(e + " - " + e.line);}

          }//sfw nearest size

      }

}

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 backGroundCounter = 1;

            if(activeDocument.artLayers.length > 0){

            backGroundCounter = activeDocument.artLayers[activeDocument.artLayers.length - 1].isBackgroundLayer ? 0 : 1;

            }

      var ref = new ActionReference();

  ref.putProperty(charIDToTypeID("Prpr"), stringIDToTypeID("targetLayers"));

      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++){

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

          }

      if(app.version.match(/^\d+/) > 15) return selectedLayers ;

       }else{

           if(app.version.match(/^\d+/) > 15) return selectedLayers ;

         var ref = new ActionReference();

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

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

         if(!backGroundCounter){

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

            }else{

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

                }

     var vis = app.activeDocument.activeLayer.visible;

        if(vis == true) app.activeDocument.activeLayer.visible = false;

        var desc9 = new ActionDescriptor();

    var list9 = new ActionList();

    var ref9 = new ActionReference();

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

    list9.putReference( ref9 );

    desc9.putList( charIDToTypeID("null"), list9 );

    executeAction( charIDToTypeID("Shw "), desc9, DialogModes.NO );

    if(app.activeDocument.activeLayer.visible == false) selectedLayers.shift();

        app.activeDocument.activeLayer.visible = vis;

      }

      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 deselectLayers() {

    var desc01 = new ActionDescriptor();

        var ref01 = new ActionReference();

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

    desc01.putReference( charIDToTypeID('null'), ref01 );

    executeAction( stringIDToTypeID('selectNoLayers'), desc01, DialogModes.NO );

};

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() {

    var desc29 = new ActionDescriptor();

        var ref23 = new ActionReference();

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

    desc29.putReference( charIDToTypeID('null'), ref23 );

    executeAction( stringIDToTypeID('selectAllLayers'), desc29, DialogModes.NO );

}

function getActionSets() {

cTID = function(s) { return app.charIDToTypeID(s); };

sTID = function(s) { return app.stringIDToTypeID(s); };

  var i = 1;

  var sets = []; 

  while (true) {

    var ref = new ActionReference();

    ref.putIndex(cTID("ASet"), i);

    var desc;

    var lvl = $.level;

    $.level = 0;

    try {

      desc = executeActionGet(ref);

    } catch (e) {

      break;  

    } finally {

      $.level = lvl;

    }

    if (desc.hasKey(cTID("Nm  "))) {

      var set = {};

      set.index = i;

      set.name = desc.getString(cTID("Nm  "));

      set.toString = function() { return this.name; };

      set.count = desc.getInteger(cTID("NmbC"));

      set.actions = [];

      for (var j = 1; j <= set.count; j++) {

        var ref = new ActionReference();

        ref.putIndex(cTID('Actn'), j);

        ref.putIndex(cTID('ASet'), set.index);

        var adesc = executeActionGet(ref);

        var actName = adesc.getString(cTID('Nm  '));

        set.actions.push(actName);

      }

      sets.push(set);

    }

    i++;

  }

  return sets;

};

function getActions(aset) {

cTID = function(s) { return app.charIDToTypeID(s); };

sTID = function(s) { return app.stringIDToTypeID(s); };

  var i = 1;

  var names = [];

  if (!aset) {

    throw "Action set must be specified";

  } 

  while (true) {

    var ref = new ActionReference();

    ref.putIndex(cTID("ASet"), i);

    var desc;

    try {

      desc = executeActionGet(ref);

    } catch (e) {

      break;   

    }

    if (desc.hasKey(cTID("Nm  "))) {

      var name = desc.getString(cTID("Nm  "));

      if (name == aset) {

        var count = desc.getInteger(cTID("NmbC"));

        var names = [];

        for (var j = 1; j <= count; j++) {

          var ref = new ActionReference();

          ref.putIndex(cTID('Actn'), j);

          ref.putIndex(cTID('ASet'), i);

          var adesc = executeActionGet(ref);

          var actName = adesc.getString(cTID('Nm  '));

          names.push(actName);

        }

        break;

      }

    }

    i++;

  }

  return names;

};

function tabInterface(onOff) {

if(onOff == undefined) onOff=true;

    var desc19 = new ActionDescriptor();

        var ref8 = new ActionReference();

        ref8.putProperty( charIDToTypeID('Prpr'), stringIDToTypeID('interfacePrefs') );

        ref8.putEnumerated( charIDToTypeID('capp'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );

    desc19.putReference( charIDToTypeID('null'), ref8 );

        var desc20 = new ActionDescriptor();

        desc20.putBoolean( charIDToTypeID('EGst'), true );

        desc20.putBoolean( stringIDToTypeID('openNewDocsAsTabs'), onOff );

    desc19.putObject( charIDToTypeID('T   '), stringIDToTypeID('interfacePrefs'), desc20 );

    executeAction( charIDToTypeID('setd'), desc19, DialogModes.NO );

};

function isTabInterface(){

var ref = new ActionReference();

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

return executeActionGet(ref).getObjectValue(stringIDToTypeID('interfacePrefs')).getBoolean(stringIDToTypeID( 'openNewDocsAsTabs'));

};

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,Comp){

tiffSaveOptions = new TiffSaveOptions();

tiffSaveOptions.embedColorProfile = true;

tiffSaveOptions.transparency = true;

tiffSaveOptions.alphaChannels = true;

tiffSaveOptions.layers = true;

switch (Number(Comp)){

    case 0 : tiffSaveOptions.imageCompression = TIFFEncoding.TIFFLZW; break;

    case 1 : tiffSaveOptions.imageCompression = TIFFEncoding.TIFFZIP; break;

    case 2 : tiffSaveOptions.imageCompression = TIFFEncoding.JPEG; break;

    case 3 : tiffSaveOptions.imageCompression = TIFFEncoding.NONE; break;

    default : break;

}

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

}

function SavePSD(saveFile){

psdSaveOptions = new PhotoshopSaveOptions();

psdSaveOptions.embedColorProfile = true;

psdSaveOptions.alphaChannels = true; 

psdSaveOptions.layers = 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){

    try{

jpgSaveOptions = new JPEGSaveOptions();

jpgSaveOptions.embedColorProfile = true;

jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;

jpgSaveOptions.matte = MatteType.NONE;

jpgSaveOptions.quality = jpegQuality;

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

}catch(e){$.writeln(e+" - "+e.line);}

}

function SaveForWeb(saveFile,jpegQuality) {

var sfwOptions = new ExportOptionsSaveForWeb();

   sfwOptions.format = SaveDocumentType.JPEG;

   sfwOptions.includeProfile = false;

   sfwOptions.interlaced = 0;

   sfwOptions.optimized = true;

   sfwOptions.quality = Number(jpegQuality);

activeDocument.exportDocument(saveFile, ExportType.SAVEFORWEB, sfwOptions);

}

function savePCX(saveFile) {

var desc = new ActionDescriptor();

desc.putString( charIDToTypeID('As  '), "PCX" );

desc.putPath( charIDToTypeID('In  '), new File( saveFile ) );

executeAction( charIDToTypeID('save'), desc, DialogModes.NO );

};

function saveAsPNG24SFW(fileName) {

    var desc3 = new ActionDescriptor();

        var desc4 = new ActionDescriptor();

        desc4.putEnumerated( charIDToTypeID('Op  '), charIDToTypeID('SWOp'), charIDToTypeID('OpSa') );

        desc4.putEnumerated( charIDToTypeID('Fmt '), charIDToTypeID('IRFm'), charIDToTypeID('PN24') );

        desc4.putBoolean( charIDToTypeID('Intr'), false );

        desc4.putBoolean( charIDToTypeID('Trns'), true );

        desc4.putBoolean( charIDToTypeID('Mtt '), false );

        desc4.putInteger( charIDToTypeID('MttR'), 255 );

        desc4.putInteger( charIDToTypeID('MttG'), 255 );

        desc4.putInteger( charIDToTypeID('MttB'), 255 );

        desc4.putBoolean( charIDToTypeID('SHTM'), false );

        desc4.putBoolean( charIDToTypeID('SImg'), true );

        desc4.putBoolean( charIDToTypeID('SSSO'), false );

            var list1 = new ActionList();

        desc4.putList( charIDToTypeID('SSLt'), list1 );

        desc4.putBoolean( charIDToTypeID('DIDr'), false );

        desc4.putPath( charIDToTypeID('In  '), new File( fileName ) );

    desc3.putObject( charIDToTypeID('Usng'), stringIDToTypeID('SaveForWeb'), desc4 );

    executeAction( charIDToTypeID('Expr'), desc3, DialogModes.NO );

};

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 ,
Oct 31, 2017

Copy link to clipboard

Copied

I can confirm that the massive code dump above (sorry), works as layer saver in PS CC 2017

Thanks Davide an Paul Riggot for that

Very happy now, works perfectly and it seems to be quicker now

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 05, 2020

Copy link to clipboard

Copied

In 2020 i needed to change the following line to make it work:

2171    ref.putIndex(1283027488, idx);

 

 

 change to:

 

2171    ref.putIndex(1283027488, idx[0]);

 

 AND I needed to run the script from ExtendScript Toolkit...

- it didn't work if I ran it directly in Photoshop from File -> Scripts -> Browse

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...