Skip to content

Instantly share code, notes, and snippets.

@jpdevries
Created May 2, 2013 22:16
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jpdevries/5505905 to your computer and use it in GitHub Desktop.
Save jpdevries/5505905 to your computer and use it in GitHub Desktop.
Export PhotoShop Layers as .png (save as a .jsx file open in Adobe ExtendScript Toolkit)
// layerName.jsx
// Copyright 2006-2008
// Written by Jeffrey Tranberry
// Photoshop for Geeks Version 2.0
/*
Description:
Using an alert(); to display current Layer's name.
Set the name of the current layer to a string "Timmy"
*/
// enable double clicking from the
// Macintosh Finder or the Windows Explorer
#target photoshop
// Make Photoshop the frontmost application
app.bringToFront();
// Pops open a dialog for the user to
// set the output folder
var outputFolder = Folder.selectDialog("Select a folder for the output files");
// Get the layers length
var docLayers = app.activeDocument.layers;
var len = docLayers.length;
// Start an xml object
// Store the original visibility properties of the layers so we can set them back when done
// Then set all layer visibility to false
var originalVisibility = new Array();
for(var i = 0; i < len; i++)
{
originalVisibility[i] = docLayers[i].visible;
docLayers[i].visible = false;
}
docLayers[0].visible = true;
for(i = 0; i < app.activeDocument.layers.length - 1; i++) {
var _curLayer = docLayers[i];
//if(originalVisibility[i] == false) continue;
_curLayer.visible = true;
docLayers[0].visible = true;
docLayers[app.activeDocument.layers.length - 1].visible = true;
//Saves as a PNG to the selected folder
var pngOptions = new PNGSaveOptions();
pngOptions.interlaced = false;
app.activeDocument.saveAs( File( outputFolder + "/" + _curLayer.name + ".png"), pngOptions, true);
_curLayer.visible = false;
//var tmpProdTagsXML = new XML("<tags></tags>");
//tmpTagsXML.text(typeTag + ",products");
}
@dnyaneshlb
Copy link

Nice one. It helped me a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment