I found this piece of script offer by a solution on exactly what I try to do here. But I have no idea and can find no related info about this jsx script. I wonder where should I put it or use it in Adobe Photoshop CS6? I tried to use the script with Script->browse and double click on the file named script.jsx where I pasted the code below for export each layer into a file that has SAME background layer applied instead of the default transparent background. However, after I used it, nothing really happened and no error pop up. So I am not sure if anything I have done is not correct.

// variables
var destination = "C:/Users/...../"
var doc = app.activeDocument;
var artlayers = new Array();

// jpeg options
var options = new ExportOptionsSaveForWeb();
options.quality = 80;
options.format = SaveDocumentType.JPEG; 

// loop through all layers
var x = 0;
var a = 0;
while (x < doc.layers.length) {
    // check if the layer is a item
    if (doc.layers[x].kind == LayerKind.NORMAL) {
        // add to array
        artlayers[a] = x;

var x = 0;
var a = 0;

for  (x=0; x < artlayers.length; x++)

doc.layers[artlayers[x]].visible = true;
// export as jpeg
try { doc.backgroundLayer.visible = true; } catch (e) {}
file = new File(destination + doc.layers[artlayers[x]].name +".jpg");
doc.exportDocument(file, ExportType.SAVEFORWEB, options); 
doc.layers[artlayers[x]].visible = false;


  • Please add the code here too. Suppose the link you gave is down, then your question is not very clear. And please descibe here what is you problem. Do you think people enjoy it to switch to another side to read your real question?
    – Mensch
    Commented Nov 2, 2014 at 13:49
  • @Kurt Updated, plz feel free let me know any other info you need :)
    – Adam
    Commented Nov 2, 2014 at 14:01

1 Answer 1


The script does work if you mess around with it a bit. And yes, joojaa is correct, it is a JSX.

Line 2 needs to be changed to an actual destination using slashes instead of backslashes, plus a semicolon at the end. I.e.,

 var destination = "C:/Users/USERNAME/FOLDER/";

You could also alter line 9 to

 options.quality = 100;

if you aren't actually saving for web and want to retain as much of the file's original quality as you can since this script is turning your PSD into a bunch of JPGs instead of PNGs.

I think you'll have to use the Browse function to utilize the script. PS doesn't seem to recognize its existence if you put it into Presets\Scripts.

That's as far as I can take it. I'm not a coder.

  • Semicolon is not mandatory, tough the auto line separator is a bit quirky.
    – joojaa
    Commented Nov 2, 2014 at 15:39
  • @joojaa — One of the errors PS was throwing made me think it needed the semicolon, so I threw it in. Never bothered to check whether it actually did anything. As I said, I'm not a coder, I'm a mess-around-er.
    – pbr
    Commented Nov 2, 2014 at 16:13
  • Its called cut and paste scripting. It is a precursor to either moving into more serious realm. Its like a gateway drug, it just takes a bit longer to get there.
    – joojaa
    Commented Nov 2, 2014 at 17:11
  • I stand accused.
    – pbr
    Commented Nov 2, 2014 at 17:38
  • @pbr I can't really comprehend where it find that background layer though... How it determine ... which layer to pick as background layer for all the jpg generations?
    – Adam
    Commented Nov 2, 2014 at 19:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.