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;
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.
Copy link to clipboard
Copied
Thanks for the answer. What do you mean link to the thread this was taken from? I created this.
Copy link to clipboard
Copied
If the answer is correct then mark it so, if not ask more questions 😉
Sometimes people create new threads based on snippets ftom others.