Skip to main content
brian_p_dts
Community Expert
Community Expert
February 21, 2024
Question

Trouble using script to save PSD as PNG

  • February 21, 2024
  • 1 reply
  • 471 views

Hi all, 

I have the following code to resize and save a PSD as a PNG. It was working fine, and still works for some psds, but frequently I am getting a user Save a Copy prompt at the doc.saveAs line. Is there something I'm missing? 

 

var path = File.openDialog().fsName;
    app.rulerUnits = Units.PIXELS;
    var pngOpts = new PNGSaveOptions;
    try {
        var doc = app.open(File(path));
    } catch(e) {
        alert("Could not open psd file " + path + ". " + e);
        return;
    }
    if (doc.width > 1500) {
        doc.resizeImage(1500, null);
    }
    var goodPath = path.replace(/psd|b$/gi,"png");
    doc.saveAs(File(goodPath), pngOpts, true);
    doc.close(SaveOptions.DONOTSAVECHANGES);

 

This topic has been closed for replies.

1 reply

Stephen Marsh
Community Expert
Community Expert
February 21, 2024

Do you have legacy save as set in your file handling preferences?

brian_p_dts
Community Expert
Community Expert
February 21, 2024

I did not. I tried enabling it; same result. Which should it be set at? 

Stephen Marsh
Community Expert
Community Expert
February 21, 2024

OK, so that wasn't the answer for the script.

 

It needs to be set at whatever your preference is!  :]

 

https://helpx.adobe.com/photoshop/using/saving-images.html#save-as

 

When you get the prompt, what colour mode and bit depth is the file?