Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


SaveAs() function throwing error

New Here ,
Jul 27, 2021 Jul 27, 2021

Copy link to clipboard

Copied

I have a script that resizes pictures and then writes them somewhere else. The saveAs() function keeps giving me the error "General Photoshop Error occurred. This functionality may not be avaiable yet in this version of photoshop."

 

Here is my script

var startRulerPreferences = app.preferences.rulerUnits;
var startTypeUnits = app.preferences.typeUnits;
var startDisplayDialogs = app.displayDialogs;
var jpegOptions = new JPEGSaveOptions();

app.preferences.rulerUnits = Units.PIXELS;
app.preferences.typeUnits = TypeUnits.PIXELS;
app.displayDialogs = DialogModes.NO;

var dateObj = new Date();
var year = dateObj.getFullYear().toString().substr(-2);
var month = ("0" + (dateObj.getMonth() + 1)).slice(-2);
var day = ("0" + dateObj.getDate()).slice(-2);

var files = File.openDialog ('Chose Files', true);
var folder = new Folder ("C:\02_Misc" + year + "_" + month + "_" + day);


for (var i = 0; i < files.length; i++){
var openDoc = app.open(File(files[i]));
app.ActiveDocument = files[i];
openDoc.resizeImage(2550, 3300, 300);
jpegOptions.quality = 8;


openDoc.saveAs(new File (folder + openDoc.name + ".jpg"), jpegOptions, true, Extension.LOWERCASE);
openDoc.Close(SaveOptions.DONOTSAVECHANGES);
}

app.preferences.rulerUnits = startRulerPreferences;
app.preferences.typeUnits = startTypeUnits;
app.preferences.displayDialogs = startDisplayDialogs;

TOPICS
Actions and scripting, Windows

Views

63

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
Adobe Community Professional ,
Jul 27, 2021 Jul 27, 2021

Copy link to clipboard

Copied

You made few mistakes. Change 4 lines from your code to correct ones:

 

Folder(File(folder = "/C/02_Misc" + year + "_" + month + "_" + day + '/')).create();

//activeDocument = openDoc;

openDoc.saveAs(new File (folder + openDoc.name.split(/\..{3}/i)[0] + ".jpg"), jpegOptions, true, Extension.LOWERCASE);
openDoc.close(SaveOptions.DONOTSAVECHANGES);

 

Also please link us to a thread this code was taken from.

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
New Here ,
Jul 28, 2021 Jul 28, 2021

Copy link to clipboard

Copied

Thanks for the answer. What do you mean link to the thread this was taken from? I created this.

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
Adobe Community Professional ,
Jul 28, 2021 Jul 28, 2021

Copy link to clipboard

Copied

LATEST

If the answer is correct then mark it so, if not ask more questions 😉

 

Sometimes people create new threads based on snippets ftom others.

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