Skip to main content
Inspiring
April 5, 2024
Answered

Is it possible to save png file without png format option dialogue?

  • April 5, 2024
  • 3 replies
  • 1644 views

I need to save png file again and again. I need to decide its name and where to save manually but I would like to use same png format option and avoid its dialogue box popoing up everytime I save file as png. quick export as PNG is desireable but it can not be recorded as action. Is it possible to do that using jsx?

This topic has been closed for replies.
Correct answer r-bin

 

try {

var folder;

try { folder = activeDocument.path; } catch(e) { folder = new Folder(); }

var nm = activeDocument.name;

var n = nm.lastIndexOf(".");
if (n > 0) nm = nm.substr(0, n);

var file = new File (folder.fsName + "/" + nm);

file = file.saveDlg("Save As", "*.png");

if (file)
    {
    var d = new ActionDescriptor();
    var d1 = new ActionDescriptor();
    d1.putEnumerated(stringIDToTypeID("method"), stringIDToTypeID("PNGMethod"), stringIDToTypeID("quick"));
    d1.putEnumerated(stringIDToTypeID("PNGInterlaceType"), stringIDToTypeID("PNGInterlaceType"), stringIDToTypeID("PNGInterlaceNone"));
    d1.putEnumerated(stringIDToTypeID("PNGFilter"), stringIDToTypeID("PNGFilter"), stringIDToTypeID("PNGFilterAdaptive"));
    d1.putInteger(stringIDToTypeID("compression"), 9);
    d.putObject(stringIDToTypeID("as"), stringIDToTypeID("PNGFormat"), d1);
    d.putPath(stringIDToTypeID("in"), file);
    d.putBoolean(stringIDToTypeID("copy"), true);
    executeAction(stringIDToTypeID("save"), d, DialogModes.NO);
    }

} catch (e) { alert(e.line+ "\n\n" +e); }

 

3 replies

r-binCorrect answer
Legend
April 6, 2024

 

try {

var folder;

try { folder = activeDocument.path; } catch(e) { folder = new Folder(); }

var nm = activeDocument.name;

var n = nm.lastIndexOf(".");
if (n > 0) nm = nm.substr(0, n);

var file = new File (folder.fsName + "/" + nm);

file = file.saveDlg("Save As", "*.png");

if (file)
    {
    var d = new ActionDescriptor();
    var d1 = new ActionDescriptor();
    d1.putEnumerated(stringIDToTypeID("method"), stringIDToTypeID("PNGMethod"), stringIDToTypeID("quick"));
    d1.putEnumerated(stringIDToTypeID("PNGInterlaceType"), stringIDToTypeID("PNGInterlaceType"), stringIDToTypeID("PNGInterlaceNone"));
    d1.putEnumerated(stringIDToTypeID("PNGFilter"), stringIDToTypeID("PNGFilter"), stringIDToTypeID("PNGFilterAdaptive"));
    d1.putInteger(stringIDToTypeID("compression"), 9);
    d.putObject(stringIDToTypeID("as"), stringIDToTypeID("PNGFormat"), d1);
    d.putPath(stringIDToTypeID("in"), file);
    d.putBoolean(stringIDToTypeID("copy"), true);
    executeAction(stringIDToTypeID("save"), d, DialogModes.NO);
    }

} catch (e) { alert(e.line+ "\n\n" +e); }

 

Inspiring
April 9, 2024

yours works fine. thank you.

Legend
April 5, 2024

I use Save for Web in a recorded action and there is no dialog box.

Inspiring
April 6, 2024

but save for web is too slow. 

D Fosse
Community Expert
Community Expert
April 6, 2024

It's not slow if the image is a sensible size for web to begin with. So have an Image size step in the action before it goes to SFW.

 

Scripts > Fit Image is perfect for that.

Stephen Marsh
Community Expert
Community Expert
April 5, 2024

@Rodan_Shiner – Yes, here it is for JPEG. If you know scripting, you can simply adapt the script for Save As PNG or Export > Save for Web (Legacy) PNG.

/*
Custom JPEG Save As to Baseline Standard.jsx
https://community.adobe.com/t5/photoshop-ecosystem-ideas/option-to-disable-quot-jpeg-options-quot-pop-up-after-saving/idc-p/12662182#M12329
Stephen Marsh, 15th January 2022 - v1.1
Info: Uses a custom prompt interface to *SAVE A COPY* with quality level 10 standard/baseline JPEG to a user selected-folder
*/

#target photoshop

if (app.documents.length !== 0) {
	// Remove extension
	var docName = app.activeDocument.name.replace(/\.[^\.]+$/, '');
	var docNameInput = prompt('Enter a filename (without extension):', docName);
	// Remove extension
	var docNameOutput = docNameInput.replace(/\.[^\.]+$/, '');
	var docPath = Folder.selectDialog('Select a folder to save the JPEG image to...');

	// File Path & Naming
	var saveFileJPEG = new File(docPath + '/' + docNameOutput + '.jpg');

	if (saveFileJPEG.exists) {
		// true = 'No' as default active button
		if (!confirm("File exists, overwrite: Yes or No?", true))
			// throw alert("Script cancelled!");
			throw null;
	}

	jpegOptions(saveFileJPEG);

	// JPEG Options
	function jpegOptions(saveFileJPEG) {
		jpgSaveOptions = new JPEGSaveOptions();
		jpgSaveOptions.embedColorProfile = true;
		jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
		jpgSaveOptions.matte = MatteType.NONE;
		jpgSaveOptions.quality = 10;
		// Save as
		activeDocument.saveAs(saveFileJPEG, jpgSaveOptions, true, Extension.LOWERCASE);
	}

	app.beep();
	// alert('JPEG saved!');

} else {
	alert('You must have a document open!');
}
Inspiring
April 6, 2024

I tried to use it but dialogue box pops up. I don't know how to remoeve it.

Stephen Marsh
Community Expert
Community Expert
April 6, 2024
quote

I tried to use it but dialogue box pops up. I don't know how to remoeve it.


By @Rodan_Shiner

 

Yes, a dialog pops-up, you stated that:

 

"I need to decide its name and where to save manually "

 

This is what the script does, it offers a dialog to enter the file name and a folder selection to save to. It doesn't pop up a dialog to set the PNG options, which are hard-coded into the script.

 

How/where do you propose that the name and save location is performed manually?

 

For what it's worth, here is the code updated for PNG:

 

/*
Custom PNG Save As without Standard Dialogs.jsx
https://community.adobe.com/t5/photoshop-ecosystem-discussions/is-it-possible-to-save-png-file-without-png-format-option-dialogue/m-p/14539007#M798627
v1.0, 6th April 2024 - Stephen Marsh
v1.1, 9th April 2024 - Changed Save As to Save a Copy
Info: Uses a custom prompt interface to *SAVE AS* PNG to a user selected-folder
*/

#target photoshop

if (app.documents.length !== 0) {
	// Remove extension
	var docName = app.activeDocument.name.replace(/\.[^\.]+$/, '');
	var docNameInput = prompt('Enter a filename (without extension):', docName);
	// Remove extension
	var docNameOutput = docNameInput.replace(/\.[^\.]+$/, '');
	var docPath = Folder.selectDialog('Select a folder to save the PNG image to...');

	// File Path & Naming
	var saveFilePNG = new File(docPath + '/' + docNameOutput + '.png');

	if (saveFilePNG.exists) {
		// true = 'No' as default active button
		if (!confirm("File exists, overwrite: Yes or No?", true))
			// throw alert("Script cancelled!");
			throw null;
	}

	pngOptions(saveFilePNG);

	// PNG Options
	function pngOptions(saveFilePNG) {
		pngSaveOptions = new PNGSaveOptions();
		pngSaveOptions.compression = 0; // 0-9
		pngSaveOptions.interlaced = false;
		// Save a Copy
		activeDocument.saveAs(saveFilePNG, pngSaveOptions, true, Extension.LOWERCASE);
	}

	app.beep();
	// alert('PNG saved!');

} else {
	alert('You must have a document open!');
}