Copy link to clipboard
Copied
I have a script that I'm using in a action to save the current file in a specific Folder.
It worked fine until I upgraded my phothoshop version.
This is the current error that I'm getting:
This functionality might not be available in this version of Photoshop.
Photoshop Version 23.0.0
This is the Script:
var JPGquality = 12;
var suffix='_03';
var docPath = app.activeDocument.path;
var docName = app.activeDocument.name.replace(/\.[^\.]+$/, '');
var suffix = '_0';
var tries = 0;
var saveFile = new File(docPath + '/Exported/' + docName + suffix + tries + '.jpg');
var fileExists = saveFile.exists;
tries++;
while (fileExists) {
saveFile = new File(docPath + '/Exported/' + docName + suffix + tries + '.jpg');
tries++;
fileExists = saveFile.exists;
}
SaveJPEG(saveFile, JPGquality);
function SaveJPEG(saveFile, jpegQuality) {
jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.embedColorProfile = true;
jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
jpgSaveOptions.matte = MatteType.NONE;
jpgSaveOptions.quality = JPGquality; //1-12
activeDocument.saveAs(saveFile, jpgSaveOptions, true, Extension.LOWERCASE);
}
It fails in the last line while trying to invoce saveAs
I also tried with app.activeDocument.saveAs(........)
I see no problems; have you made sure the Folder exists and the file’s name contains no illegal character?
Do you have 'Exported' subfolder in the folder your file was open from?
Copy link to clipboard
Copied
I see no problems; have you made sure the Folder exists and the file’s name contains no illegal character?
Copy link to clipboard
Copied
Folder exists, but you bring a good point it might not be in the right path
Copy link to clipboard
Copied
Do you have 'Exported' subfolder in the folder your file was open from?
Copy link to clipboard
Copied
ohhhh you hit the nail in the head!
The Folder is actually outside of the docPath. (/../Exported)
Thanks a lot for brining this knowlege forward!
Copy link to clipboard
Copied
Does your script work now?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
@HecOsbRod I thought that the following addition may help, where I have added a check to create the export folder if it does not currently exist in the save path. This should automatically avoid the issue.
var JPGquality = 12;
var suffix='_03';
var docPath = app.activeDocument.path;
var outputFolder = new Folder(decodeURI(docPath) + '/' + 'Exported');
var docName = app.activeDocument.name.replace(/\.[^\.]+$/, '');
var suffix = '_0';
var tries = 0;
var saveFile = new File(outputFolder + '/' + docName + suffix + tries + '.jpg');
var fileExists = saveFile.exists;
if (outputFolder.exists === false) outputFolder.create();
tries++;
while (fileExists) {
saveFile = new File(outputFolder + '/' + docName + suffix + tries + '.jpg');
tries++;
fileExists = saveFile.exists;
}
SaveJPEG(saveFile, JPGquality);
function SaveJPEG(saveFile, JPGquality) {
jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.embedColorProfile = true;
jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
jpgSaveOptions.matte = MatteType.NONE;
jpgSaveOptions.quality = JPGquality; //1-12
activeDocument.saveAs(saveFile, jpgSaveOptions, true, Extension.LOWERCASE);
}