Last Updated: February 25, 2016
·
2.696K
· denver

ExtendScript (Photoshop, InDesign, Illustrator) export selection as PNG

Using ExtendScript Toolkit you can create scripts for use in Photoshop, InDesign and Illustrator. The documentation isn't quite good, but if you want to save the selection as separate transparent PNG's, use this:

var prefixFilename = prompt("Filename:", "layer");

for ( var i = 0; i < app.selection.length; i++ )
{
        var myFile = File("~/Desktop/"+prefixFilename+"-"+i+".png"); // Works on Mac. Use another path for Windows
        app.selection[i].exportFile(ExportFormat.PNG_FORMAT, myFile, true);
}

For saving the selection as separate JPG's, use this:

var prefixFilename = prompt("Filename:", "layer");

for ( var i = 0; i < app.selection.length; i++ )
{
        var myFile = File("~/Desktop/"+prefixFilename+"-"+i+".jpg"); // Works on Mac. Use another path for Windows
        app.selection[i].exportFile(ExportFormat.JPG, myFile, false);
}