Copy link to clipboard
Copied
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?
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(s
...
Copy link to clipboard
Copied
@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!');
}
Copy link to clipboard
Copied
I tried to use it but dialogue box pops up. I don't know how to remoeve it.
Copy link to clipboard
Copied
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!');
}
Copy link to clipboard
Copied
when you save as png using "save as" you need to decide how much it is compressed and If you need interlace or not. it's "png format option" I would like to ommit because I need to save same png file again and again. I tried new one and still "png format option" pops up.
Copy link to clipboard
Copied
I understand... The PNG options are hard-coded into the script, you don't need to select them (caveat: if the source file is flattened).
You said that you need to decide what the filename is, which is what the script does:
I need to decide its name
Additionally, you also stated that you need to specify where to save, which is what the script does:
...and where to save manually
But you don't need to select the PNG options, they are baked into the script code. But if you have layers, then the format dialog will pop up defaulting to Photoshop format... For what it's worth, I'll update the code to ensure that the file is suitable for PNG before saving.
EDIT:
I have updated the script to a 1.1 version, changing the following from save as:
// Save as
activeDocument.saveAs(saveFilePNG, pngSaveOptions, false, Extension.LOWERCASE);
To use a "true" boolean to save a copy:
// Save a Copy
activeDocument.saveAs(saveFilePNG, pngSaveOptions, true, Extension.LOWERCASE);
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Stephen_A_Marsh, you are using the DOM saveAs method to save as PNG. Could you check if this bug has been fixed with this function in the latest Photoshop? If not, then such saveing may lead to undesirable results.
By @r-bin
@r-bin – thank you, I was not aware of this DOM bug. I'll test and report back, thank you!
Copy link to clipboard
Copied
yours works fine now. and now I've found out quick export as PNG has a flaw. Why it trims transparent area...
I will use yours or r-bin's anyway.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
I use Save for Web in a recorded action and there is no dialog box.
Copy link to clipboard
Copied
but save for web is too slow.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
mine is not sensible size. because it's huge texutre file for 3D model.
Copy link to clipboard
Copied
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); }
Copy link to clipboard
Copied
yours works fine. thank you.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now