• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

177

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
LEGEND ,
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.

Votes

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.

Votes

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
LEGEND ,
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.

Votes

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