// configuration var exportExtension = "jpg"; // extension jpg or png var exportPath = "/Users/kasparsj/Work/someproject/images"; // set to your project path app.preferences.RulerUnits = Units.PIXELS; var doc = app.activeDocument; var html = ''; var exportOptions = new ExportOptionsSaveForWeb(); exportOptions.quality = 80; // set quality if (exportExtension == "jpg") { exportOptions.format = SaveDocumentType.JPEG; } else { exportOptions.format = SaveDocumentType.PNG; } // do it! processLayerSet(doc); // loops trough all layers and processes visible Art Layers function processLayerSet(layer) { for (var i=0; i<layer.layerSets.length; i++) { if (layer.layerSets[i].visible) { processLayerSet(layer.layerSets[i]); } } for (i=0; i<layer.artLayers.length; i++) { if (layer.artLayers[i].visible) { processArtLayer(layer.artLayers[i], i); } } } function processArtLayer(layer, index) { // copy layer doc.activeLayer = layer; doc.selection.deselect(); doc.selection.selectAll(); doc.selection.copy(); // create new doc, paste and crop var newDoc = app.documents.add(1920, 1080, 72, layer.name); newDoc.paste(); newDoc.selection.selectAll() intersectSelectionWithTransparency() newDoc.crop(newDoc.selection.bounds) // save new doc newDoc.exportDocument(new File(exportPath+"/"+layer.name+"."+exportExtension), ExportType.SAVEFORWEB, exportOptions); newDoc.close(SaveOptions.DONOTSAVECHANGES); } function intersectSelectionWithTransparency(){ var desc = new ActionDescriptor(); var ref = new ActionReference(); ref.putEnumerated( charIDToTypeID( "Chnl" ), charIDToTypeID( "Chnl" ), charIDToTypeID( "Trsp" ) ); desc.putReference( charIDToTypeID( "null" ), ref ); var ref1 = new ActionReference(); ref1.putProperty( charIDToTypeID( "Chnl" ), charIDToTypeID( "fsel" ) ); desc.putReference( charIDToTypeID( "With" ), ref1 ); executeAction( charIDToTypeID( "Intr" ), desc, DialogModes.NO ); }