Skip to main content
Participant
August 29, 2017
Answered

ExtendScript Save PNG as JPEG without dialog

  • August 29, 2017
  • 2 replies
  • 2588 views

I've written a script in ExtendScript to process hundreds of image files. It works fine without any intervention if the original files are JPEGs. I however have started getting some PNG's. The script opens them fine and converts them to RGB. I set my JPEG save Options but when PS goes to save it brings up the Save As dialog box. Is there any way to avoid the dialog box?

My code:

var destFile = File(printFolder.fullName + "/" + doc.name);

var saveOptions = new JPEGSaveOptions( ); 

saveOptions.embedColorProfile = true;

saveOptions.quality = 12;

saveOptions.formatOptions = FormatOptions.STANDARDBASELINE; 

saveOptions.matte = MatteType.NONE; 

    

doc.saveAs (destFile, saveOptions, false );

This topic has been closed for replies.
Correct answer Chuck Uebele

Have you tried adding this to your code:

app.displayDialogs = DialogModes.NO;

2 replies

Chuck Uebele
Community Expert
Chuck UebeleCommunity ExpertCorrect answer
Community Expert
August 29, 2017

Have you tried adding this to your code:

app.displayDialogs = DialogModes.NO;

barrykfmcAuthor
Participant
August 29, 2017

Thanks Guys. Both options worked for me.

Tomas Sinkunas
Legend
August 29, 2017

Try this out.

function saveJPG(saveFile, jpegQuality) {

    saveFile = (saveFile instanceof File) ? saveFile : new File(saveFile);

    jpegQuality = jpegQuality || 7;

    var jpgSaveOptions = new JPEGSaveOptions();

    jpgSaveOptions.embedColorProfile = true;

    jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;

    jpgSaveOptions.matte = MatteType.NONE;

    jpgSaveOptions.quality = jpegQuality;

    activeDocument.saveAs(saveFile, jpgSaveOptions, true, Extension.LOWERCASE);

}