我刚开始使用 JS 和 photoshop,遇到了一些麻烦。我想要做的是去掉当前文档文件名中的“Online”这个词,然后在不同的文件夹中保存一个具有新文件名的 JPG。
在 adobe 引用资料的帮助下,我想出了以下脚本:
//Path where the final jpg should be saved
var JPGquality = 12;
var docPath="C:\Users\user\Desktop\test";
var docName='';
docName = activeDocument.name;
//Set new file name by replacing "_Online_" with "_"
var NewName = docName.replace("_Online_", "_");
var saveFile = new File(docPath+'/'+NewName+ '.jpg');
//Save JPG
function SaveJPEG(saveFile, jpegQuality) {
jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.embedColorProfile = true;
jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
jpgSaveOptions.matte = MatteType.NONE;
jpgSaveOptions.quality = jpegQuality; //1-12
activeDocument.saveAs(saveFile, jpgSaveOptions, true,Extension.LOWERCASE);
}
脚本运行通过但没有错误但没有任何反应。如果有人能告诉我我做错了什么,那将非常有帮助。希望有人能帮我弄清楚如何解决这个问题;)
最佳答案
我用这个:
function saveAsJPG() {
jpgFile = new File(outputFolder + "/" + _CardFileName + ".jpg");
jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.embedColorProfile = true;
jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
jpgSaveOptions.matte = MatteType.NONE;
jpgSaveOptions.quality = 12;
docRef.saveAs(jpgFile, jpgSaveOptions, true, Extension.LOWERCASE);
}
关于javascript - Photoshop Javascript 脚本 : Rename file and saveAs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18056685/