Copy link to clipboard
Copied
Hi
I have been using JJ Mack's script below as an action for saving JPGs for a couple of years on single open JPGs and batching JPGs using Bridge > Photosop > Batch without any problems. However, with the latest PS upgrade (24.0.0) when I try to batch JPGs using the script action I am presented with the Save As dialog box. I have tried the script with and without the app.displayDialogs lines but I'm still seeing the Save As dialog box.
If anyone can solve this problem for me I would be very grateful. Thanks in advance for any help I may receive. Cheers Leo
============================================
// app.displayDialogs = DialogModes.NO;
try {
var tmp = app.activeDocument.fullName.name;
ftype = decodeURI(tmp.substring(tmp.lastIndexOf("."),)).toLowerCase();
if (ftype==".nef" || ftype==".cr2" || ftype==".crw" || ftype==".dcs" || ftype==".raf" || ftype==".arw" || ftype==".orf") { throw "error1"; }
fname = app.activeDocument.name.replace(/\.[^\.]+$/, '');
SaveAsJPEG(activeDocument.path + "/" + fname, 10); // Quality Level 10
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES); // or (SaveOptions.SAVECHANGES) or (SaveOptions.PROMPTTOSAVECHANGES)
// alert("The document has been saved as a JPEG!");
}
catch(e) {alert("The document has not been saved yet!")}
function SaveAsJPEG(saveFile, jpegQuality){
var doc = activeDocument;
jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.embedColorProfile = true;
jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
jpgSaveOptions.matte = MatteType.NONE;
jpgSaveOptions.quality = jpegQuality;
activeDocument.saveAs(File(saveFile+".jpg"), jpgSaveOptions, true,Extension.LOWERCASE);
}
// app.displayDialogs = DialogModes.YES;
====================================
Before I dig any further, first try this action manager code version to see if there is any difference:
var savedDisplayDialogs = app.displayDialogs;
app.displayDialogs = DialogModes.NO;
try {
var tmp = app.activeDocument.fullName.name;
ftype = decodeURI(tmp.substring(tmp.lastIndexOf("."), )).toLowerCase();
if (ftype == ".nef" || ftype == ".cr2" || ftype == ".crw" || ftype == ".dcs" || ftype == ".raf" || ftype == ".arw" || ftype == ".orf") {
throw "error1";
}
fname
...
Copy link to clipboard
Copied
For Save As dialog box read Save as Copy dialog box
Copy link to clipboard
Copied
Try enabling legacy save as in file handling preferences.
Copy link to clipboard
Copied
I tried the legacy Save As and it made no diffrence 🙂
Copy link to clipboard
Copied
It should be fairly easy to include in the script steps that will make the file conform to the jpeg file format specification (flatten, convert to 8 bit, remove alpha channels). Then jpeg will be available in Save As.
In the last two PS versions, any file format that does not support all current properties of the file, is moved to Save A Copy. This was done because of policy changes in MacOS, which no longer allowed a copy to be passed off as a full original.
Copy link to clipboard
Copied
I've have read about this but I still don't understand why I can save a single file in Photoshop using the script action but it doesn't work for a batch of files.
Copy link to clipboard
Copied
Try the following self contained batch code, the input is a top-level folder of images:
#target photoshop
app.bringToFront();
if (!documents.length) {
var savedDisplayDialogs = app.displayDialogs;
var inputFolder = Folder.selectDialog('Select the input folder', '');
var inputFiles = inputFolder.getFiles();
app.displayDialogs = DialogModes.NO;
for (var a = 0; a < inputFiles.length; a++) {
try {
open(inputFiles[a]);
///// JJMACK SCRIPT /////
try {
var tmp = app.activeDocument.fullName.name;
ftype = decodeURI(tmp.substring(tmp.lastIndexOf("."), )).toLowerCase();
if (ftype == ".nef" || ftype == ".cr2" || ftype == ".crw" || ftype == ".dcs" || ftype == ".raf" || ftype == ".arw" || ftype == ".orf") {
throw "error1";
}
fname = app.activeDocument.name.replace(/\.[^\.]+$/, '');
SaveAsJPEG(activeDocument.path + "/" + fname, 10); // Quality Level 10
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES); // or (SaveOptions.SAVECHANGES) or (SaveOptions.PROMPTTOSAVECHANGES)
// alert("The document has been saved as a JPEG!");
} catch (e) {
alert("The document has not been saved yet!")
}
function SaveAsJPEG(saveFile, jpegQuality) {
jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.embedColorProfile = true;
jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
jpgSaveOptions.matte = MatteType.NONE;
jpgSaveOptions.quality = jpegQuality;
activeDocument.saveAs(File(saveFile + ".jpg"), jpgSaveOptions, true, Extension.LOWERCASE);
}
///// JJMACK SCRIPT /////
app.activeDocument.close(SaveOptions.SAVECHANGES);
} catch (e) {}
}
} else {
alert('Please close all open files before running this script');
}
Copy link to clipboard
Copied
Hi Stephen,
Thanks, the script worked for a batch of JPGs in the same folder. No messages or errors popping up.
However, I apologise for not explaining my workflow more clearly. I use the SaveAsJPG script at the end of a number of different actions and scripts. As an example, I have an action that resizes JPGs to 3000X3000 and then runs the SaveAsJPG script to save the file. If I have one or two JPGs I click the Action in the Action window in Photoshop. But, if I have 50 JPGs to resize I'd highlight them in Bridge and use Tools > Photoshop > Batch and select the same Action to resize and save the JPGs in a batch. Is it possible for your new code to be adapted to save a single file without the Save As Copy dialog popping up?
Thanks for your help, it's much appreciated and again I apologise for not explaining things more clearly.
Cheers Leo
Copy link to clipboard
Copied
It is easy enough to add a line of code into the batch script to play a specific action.
Or as requested, yes, I can replace the existing code to use Save As a Copy.
Copy link to clipboard
Copied
Is it possible for your new code to be adapted to save a single file without the Save As Copy dialog popping up? I'd prefer the code to just save a file without adding an Action to the SaveJPG script. This would then enable me to add the SaveJPG script to end of any Action or script I have created or may create in the future. I can then do the batching in Bridge using Tools > Photoshop > Batch.
The bewildering thing for me is that I have been doing this succesfully for a couple of years with the JJ Mack script without a hitch. It's only recently that the dreaded "Save As Copy" box has been popping up. My knowlege of coding is nil so I'm not sure how or whether the "Save As Copy" box can be prevented from popping up.
Copy link to clipboard
Copied
I'll need to look into this deeper, JJMack's code already has the boolean true for copy set, so something unexpected is happening.
Copy link to clipboard
Copied
Before I dig any further, first try this action manager code version to see if there is any difference:
var savedDisplayDialogs = app.displayDialogs;
app.displayDialogs = DialogModes.NO;
try {
var tmp = app.activeDocument.fullName.name;
ftype = decodeURI(tmp.substring(tmp.lastIndexOf("."), )).toLowerCase();
if (ftype == ".nef" || ftype == ".cr2" || ftype == ".crw" || ftype == ".dcs" || ftype == ".raf" || ftype == ".arw" || ftype == ".orf") {
throw "error1";
}
fname = app.activeDocument.name.replace(/\.[^\.]+$/, '');
SaveAsJPEG(10, new File(activeDocument.path + "/" + fname), true, true);
// or (SaveOptions.SAVECHANGES) or (SaveOptions.PROMPTTOSAVECHANGES)
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
// alert("The document has been saved as a JPEG!");
} catch (e) {
alert("The document has not been saved yet!")
}
app.displayDialogs = savedDisplayDialogs;
function SaveAsJPEG(extendedQuality, in2, copy, lowerCase) {
function s2t(s) {
return app.stringIDToTypeID(s);
}
var descriptor = new ActionDescriptor();
var descriptor2 = new ActionDescriptor();
descriptor2.putInteger( s2t( "extendedQuality" ), extendedQuality );
descriptor2.putEnumerated( s2t( "matteColor" ), s2t( "matteColor" ), s2t( "none" ));
descriptor.putObject( s2t( "as" ), s2t( "JPEG" ), descriptor2 );
descriptor.putPath( s2t( "in" ), in2 );
descriptor.putBoolean( s2t( "copy" ), copy );
descriptor.putBoolean( s2t( "lowerCase" ), lowerCase );
descriptor.putEnumerated( s2t( "saveStage" ), s2t( "saveStageType" ), s2t( "saveSucceeded" ));
executeAction( s2t( "save" ), descriptor, DialogModes.NO );
}
Copy link to clipboard
Copied
Hi Stephen
I have tried the code on its own to save a single file and to save a batch of files using Tools > Photoshop > Batch. I have added the script to the end of my 3000X3000 action and tried it on a single file and on a batch of files using Tools > Photoshop > Batch. Using all methods no Save As Copy window has popped up so I think you have cracked this for me.
Thank you very much, much appreciated.
I still have two questions as I can't see anything obvious in the code.
One of the main reasons I use a script to save my JPG files is to save them as Standard JPGs (rather than Baseline Optismised or Progressive). Does your code include code to save the JPG as a Standard JPG?
The code is working but I've not come across the term "action manager code version". Does this have any implications on the way I can use the code?
Thanks again for spending the time to help me with this, Cheers Leo
Copy link to clipboard
Copied
Three questions!! Is the JPG quality set to 10?
Copy link to clipboard
Copied
Yes, it is Baseline Standard, quality level 10. No optimised or progressive scans.
If you do a Save As on one the JPEG files produced by the script, the previously used settings will be shown in the interface when resaving.
Unless you are going to get into scripting, don't worry about "standard" DOM vs "esoteric" AM code. I use the ScriptingListener plugin to record the AM code (and the CleanSL script to tidy it up), while some here can actually write AM code from scratch.
Copy link to clipboard
Copied
Excellent, thanks for the confirmation and explanation. Thanks again for solving this script/coding problem. Cheers.
Copy link to clipboard
Copied
You're welcome!