Export groups to files in Photoshop
Published on June 30th, 2011
At this point the latest version of Photoshop (CS5) only offers to export layers to files. If you’re using groups (folders) in Photoshop there’s no option available to export those.
Use the following script to export all groups to high quality .png files. Copy the script below or download the script directly.
#target photoshop
function main(){
if(!documents.length) return;
var doc = activeDocument;
var oldPath = activeDocument.path;
for(var a=0;a<doc .layerSets.length;a++){
activeDocument.activeLayer = activeDocument.layers.getByName(doc.layerSets[a].name);
dupLayers();
activeDocument.mergeVisibleLayers();
activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true);
var saveFile= File(oldPath +"/"+doc.layerSets[a].name +".png");
SavePNG(saveFile);
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}
}
main();
function dupLayers() {
var desc143 = new ActionDescriptor();
var ref73 = new ActionReference();
ref73.putClass( charIDToTypeID('Dcmn') );
desc143.putReference( charIDToTypeID('null'), ref73 );
desc143.putString( charIDToTypeID('Nm '), activeDocument.activeLayer.name );
var ref74 = new ActionReference();
ref74.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
desc143.putReference( charIDToTypeID('Usng'), ref74 );
executeAction( charIDToTypeID('Mk '), desc143, DialogModes.NO );
};
function SavePNG(saveFile){
var pngOpts = new ExportOptionsSaveForWeb;
pngOpts.format = SaveDocumentType.PNG
pngOpts.PNG8 = false;
pngOpts.transparency = true;
pngOpts.interlaced = false;
pngOpts.quality = 100;
activeDocument.exportDocument(new File(saveFile),ExportType.SAVEFORWEB,pngOpts);
}
How to use this script
Copy the script and save it as a .jsx file (ExtendScript Script) anywhere on your system. In Photoshop go to the following menu item: File > Scripts > Browse… Now select the .jsx file in the file browser. Photoshop will now start exporting all your groups to files. It will save the files in the directory the .psd is located in.
Known limitations
- Empty groups give back an error message and stop the exporting proces.
- Not tested below Photoshop version CS5 (might work in lower versions).
Let me know if you find this script useful or if you run into any problems.
Reader Comments (51)
trza http://trza.us
August 15th, 2011
this is excellent but what about if you have nested groups? that’s my problem :
for example http://gyazo.com/6ff5c1fa48658a0c8c8a8c514a01b5cd.png
also nice clean site 🙂
Damien van Holten http://www.damienvanholten.com
August 17th, 2011
@trza I actually don’t know any way to handle nested groups. If I ever find out I’ll be sure to blog about it though.
Murid Rahhal
August 21st, 2011
Works great in CS4 too. Great stuff!
Worley bird http://wbirdcreative.com
April 6th, 2012
Having issues in CS5.
Error 8800: General Photoshop error occurred. This functionality may not be available in this version of Photoshop.
– The command “Make” is not currently available.
Line: 26
-> executeAction( charIDToTypeID(‘Mk ‘), desc143, DialogModes.NO );
Ika http://ikablog.com/
April 30th, 2012
Useful info Damien.
also beautiful nice site.
Matt http://www.matttrostle.com
May 6th, 2012
Worked in CS3 too! Thanks so much!!
Tomek Cejner http://www.japko.net/
June 7th, 2012
Hi!
Thanks for helpful thing! I have tinkered a little with your script and added support for nested layer groups, and ability to export of single layers as well.
You can find it here: https://gist.github.com/2892034
I hope you are okay with this – you were of course credited.
dsdf
August 28th, 2012
The script from Tomek doesn’t work. Photoshop freezes for a half minute, makes an ‘out’ folder but puts nothing in it. 🙁
dsdf
August 28th, 2012
About the original script. THANKS!!!
If i want to export nested groups, i just CTRL-click on the groups i want, right click duplicate layers to a new document, then run the script. Make sure each group has a different name. Works great!
King Arthur http://appcamelot.com
October 13th, 2012
Responding to Worley bird and anyone else that gets Error 8800 – The command “Make” is not currently available.
Make sure that the layers and groups that you are exporting are all visible and the error will go away!
Patrick
October 24th, 2012
The script works great but adds a white background to every file.? (Even though the script clearly says activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true);) Help?
Henry http://telbak.com
December 7th, 2012
what about if i want to save as psd?
Travis W http://www.travisvideo.com
December 12th, 2012
Holy crap I can’t believe that worked.
@Patrick – I just ran the script with no background and everything exported transparent.
Mark
January 9th, 2013
Thanks. This saved me a ton of time!! Thank You!
Fahad http://digitalexperts.net
January 23rd, 2013
simply want to say thanks. It is a awesome script, has made my work lot easier.
Csaba http://mynewsociallife.blogspot.hu/
January 27th, 2013
Thanks. And thanks again. Saved my life 🙂 I’ve got a PSD, with 800 groups / 1900 layers. And need each of them. Thanks again 🙂
djoni
February 10th, 2013
Thanks! It saved me a lot of times to save 35 icons!
Henrique
February 22nd, 2013
Really really really thank you!
It worked perfectly! You saved my day.
Cheers!
hannes http://hannesdelbeke.blogspot.be
March 7th, 2013
thx a lot !!
Christopher Mathews http://www.designs2day.com
March 15th, 2013
Awesome work… Its working, Thank you!
Have a Blessed Day
youhammi
March 27th, 2013
I ve used it on CS6, and it works perfectly, and it respect the names of the groups too!
thx a lot!!!
Derek
April 24th, 2013
Thank you so much. You wouldn’t believe how much timed this script has saved me!
WSetyo http://wsetyo.com
April 25th, 2013
Thanks alot!
It saved me a lot of times to export 60 groups!
what about if i want to save as jpeg files?
Goutham
April 29th, 2013
Wow the script is awesome…but i have some layers and background which is common for all the groups that is outside the folder and i want the output along with those layers too… HELP ME!!!!
cutlier http://gcgraphics.net
June 13th, 2013
This is totally awesome!!!! Thanks!
James
June 29th, 2013
Anyone know why I would be getting
Error 8103: Document has not yet been saved
“Line: 5 -> var oldPath = activeDocument.path;”
??
The document *has* been saved.
July 4th, 2013
YOU SIR! Rock.
S
July 5th, 2013
It works !
but I want to save the document size not the image size.
what about it?
Thanks again
joschi
July 9th, 2013
Thank you so much for this! you safed my a**! i aleready thought i have to export 400 grouped images manually!
with kind regards from berlin
joschi
Gunja1513
July 23rd, 2013
Worked great in CS4. Do not leave any groups with nothing in them, saving an image that is 100% transparent throws an error. This is going to be a life saver on my current project.
Rammi http://www.i-am-bored.com/bored_link.cfm?link_id=9644
July 25th, 2013
So i finally didn’t get it. I have different Folders and Layers, so i wanna like to have these Layers called with a Prefix like ‘S03’ then ‘_’ and after that the Folder name and the Layername so if i have 2 Folders with each contains 2 Layers “S03_examplefolder1_examplelayer1” “S03_examplefolder1_examplelayer2” “S03_examplefolder2_examplelayer1” “S03_examplefolder2_examplelayer2”. Which Script should i take?
atzl
September 5th, 2013
Brrrrrm! Zap! Pow! Done!
Works like a charm here (CS6).
Thank you for that!
Graham
September 19th, 2013
Freakin awesome man!
Michael
October 1st, 2013
I got:
Line: 1
-> {rtf1ansiansicpg1252cocoartf1187cocoasubrtf390
Ari
October 23rd, 2013
Awesome script. Worked perfectly. It basically turns on each group/folder and saves it out as a PNG. Awesome.
Pascal http://www.arteactive.com
October 23rd, 2013
Hi nice script, but when I open it it says:
Error 8103: the document has not yet been saved
Line:5
-> var oldPath = actuveDocument.path;
Steve
November 8th, 2013
…excellent, but any way of giving the crop/uncrop option similar to export layers as files?
Oswaldo Mendoza http://oswaldomendoza.com
January 10th, 2014
Thank you. Works like a charm on CS6.
Christine Rosas
January 13th, 2014
….and it still works like a charm in 2014!!! woohoo! Thanks for saving me a ton of work! 🙂
Erik Boman http://www.wanderingmind.net
January 23rd, 2014
Perfect – thanks!
Ryan Terry http://ryanterry.net
January 24th, 2014
I get this error when using the script (CS6). Any ideas?
Line: 1
-> {rtf1ansiansicpg1252cocoartf1187cocoasubrtf400
Lukas K. http://www.formlos-berlin.de
January 27th, 2014
I can confirm it still works like a charm in Photoshop CC and I wrote a little modification. My script exports all groups to Photoshop *.psd files: http://www.formlos-berlin.de/allgemein/photoshop-skript-alle-gruppen-einzeln-als-psd-speichern/
Maybe this is usefull for someone 🙂 Keep up the good work – greetings from Berlin!
Thelle Kristensen http://www.thelle.dk
February 5th, 2014
This script has been so useful to me! I’d like to share it – what license should I state on it? (MIT license?) Will of course credit you for it!
Leon Roy http://www.leonroy.com
February 5th, 2014
Top banana, this worked brilliantly!
Narciso http://www.narcisocarlos.com
February 13th, 2014
This worked like magic. CS5.
Thanks to the author 🙂
Mark
February 17th, 2014
Amazing script. Works like magic. Well you have to be mindful of what characters you add to group name.
Psdmaster
February 24th, 2014
Thanks, this is great script.
And howbout if I want export the groups as tif format, is it possible to modify the code??
Sathyan Velumani http://sathyanvelumani.com
March 14th, 2014
Thank you!! Saved a lot of time..
Cheers!
loothi http://triffid.org
March 18th, 2014
Any idea how I can do exactly this but leave the background layer (and therefore canvas size etc) on each exported png? Something like activeDocument.backgroundLayer.visible = true;
somewhere?
Ta muchly.
Victor
March 24th, 2014
It works for cc,too. This is so awesome for story boarding!
WPcustoms http://www.wpcustoms.net
May 6th, 2014
I’m playing around with it for a while and changed it to save psds. That works great but clipping path and alpha channels are gone. Anybody got an idea how to keep them?
Leave a comment