保存后关闭所有打开的文档

close all open documents after saving

本文关键字:文档 保存      更新时间:2023-09-26

我让脚本部分工作。它将所有打开的psd以jpg格式保存到一个单独的目录中,并关闭一些打开的文件,而不是全部。该目录有五个文件。该脚本只保存三个文件,我做错了什么?

#target photoshop
if (app.documents.length > 0) {
//flatten the active document
app.activeDocument.flatten(); 
//jpeg options
var myJPEGOptions = new JPEGSaveOptions();
myJPEGOptions.embedColorProfile = true;
myJPEGOptions.formatOptions = FormatOptions.STANDARDBASELINE;
myJPEGOptions.matte = MatteType.WHITE;
myJPEGOptions.quality = 12;
myJPEGOptions.scans = 3;
// get documents;
var docs = app.documents;
for (var m = 0; m < app.documents.length; m++) {
app.activeDocument = docs[m];
try {
//save file to folder
var myFile = new File(("~/Desktop/forum-test") + "/" + activeDocument.name); 
app.activeDocument.saveAs(myFile, myJPEGOptions, true); 
//close the document
activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}

catch (e) {
alert ("Error the script did not execute");
}
}
}

app.documents集合是动态的,因此当您关闭文档时,该集合会相应地更改。

因为在for循环中关闭文档,将递增索引与app.documents.length进行比较,所以不会处理所有文件(因为每次处理循环时app.documents.length都会减少一个)。

尝试while循环:

while (app.documents.length){
  // Save and close the active document here.
}

我认为这两行是错误的:

//save file to folder
var myFile = new File(("~/Desktop/forum-test") + "/" + activeDocument.name);

//close the document
activeDocument.close(SaveOptions.DONOTSAVECHANGES);

你不应该用app.activeDocument而不是activeDocument吗?什么是activeDocument