Action with two scripts only works once

Explorer ,
Apr 27, 2022 Apr 27, 2022

Copy link to clipboard

Copied

Hi

I would like to run the two scripts below on a number of open images using an Action.  The first script uses Image Size to make the image square using the shortest side of the image. The second script saves the image. The scripts both work when run as seperate scripts. The Action works on the first image but not on the other open images. If anyone can solve this problem for me I would be very grateful. Thanks in advance for any help I may receive. Both scripts were posted on threads here and I have tweaked them. Thanks to the original people who posted them.  Cheers Leo

 

SCRIPT ONE

=======

if(documents.length){
var doc = activeDocument;
var Width = doc.width.as('px');
var Height = doc.height.as('px');
var Max = Math.max(Width,Height);
var Min = Math.min(Width,Height);
var White = new SolidColor;
White.rgb.hexValue = 'ffffff';
backgroundColor = White;
// doc.resizeCanvas(new UnitValue(Max,"px"),new UnitValue(Max,"px"),AnchorPosition.MIDDLECENTER);
doc.resizeImage(new UnitValue(Min,"px"), new UnitValue(Min,"px"), undefined, ResampleMethod.BICUBIC);
}

=======

SCRIPT TWO

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;

==========

 

 

TOPICS
Actions and scripting

Views

56

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Adobe Community Professional , Apr 27, 2022 Apr 27, 2022
Both scripts could be combined into one, however, I tested both as separate scripts. The first script didn't require modification. The second script had issues with action recording and playback with the dialog mode lines, so I commented out the first and last lines of the script. Here is the Action, each separate script as a separate action step in a single action: Here is the Batch, using open docs as the input with the output as none, as the second scripted action step is handling th...

Likes

Translate

Translate
Adobe Community Professional ,
Apr 27, 2022 Apr 27, 2022

Copy link to clipboard

Copied

Both scripts could be combined into one, however, I tested both as separate scripts.

 

The first script didn't require modification.

 

The second script had issues with action recording and playback with the dialog mode lines, so I commented out the first and last lines of the script.

 

Here is the Action, each separate script as a separate action step in a single action:

action.png

 

Here is the Batch, using open docs as the input with the output as none, as the second scripted action step is handling the saving:

batch.png

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 27, 2022 Apr 27, 2022

Copy link to clipboard

Copied

LATEST

Thanks Stephen. That works for me too. I can't remember why I added the app.displayDialogs lines. I think it may have been because I was getting unwanted messages popping up. No unwanted messages now so all is good. Thanks again. Cheers Leo  

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines