是否有现有的 InDesign 脚本可以同时保存 INDD 文件和 IDML 副本?
我与数十名独立设计师合作开展协作项目,我们这些使用 Creative Cloud 的人必须记住为早期版本的人保存 IDML 副本。而我们经常忘记。
我希望找到或调整一个脚本,例如,添加一个名为“使用 IDML 保存”的菜单项,并将当前文档和 IDML 副本一起保存。
是否有现有的 InDesign 脚本可以同时保存 INDD 文件和 IDML 副本?
我与数十名独立设计师合作开展协作项目,我们这些使用 Creative Cloud 的人必须记住为早期版本的人保存 IDML 副本。而我们经常忘记。
我希望找到或调整一个脚本,例如,添加一个名为“使用 IDML 保存”的菜单项,并将当前文档和 IDML 副本一起保存。
这个例子应该让你开始。您需要在每个 InDesign 会话中运行一次脚本。例如,您可以将其添加为启动脚本。每次用户将文档保存为 idml 文件时,它都会保存。
#targetengine "session"
// we need a targetegine to make this work
var doc = app.activeDocument; // get the current doc
// now to the event listener
app.addEventListener('afterSave', function(theEvent) {
$.writeln('saving'); // just to see whats going on
if (!doc.saved) {
// catch those possible mistakes
alert('doc was never saved');
exit();
}
var aName = doc.name; // get the name
var newName = aName.replace("indd", "idml"); // replace the indd to idml
// crate a new File Object next to the indd
var theFile = File(File(doc.filePath).fsName + "/" + newName);
// export
doc.exportFile(ExportFormat.INDESIGN_MARKUP, theFile, false);
});
如果您想将此作为菜单命令,您可以查看关于indiscripts的这篇博文。
谢谢@fabiantheblind,效果很好。我已经对其进行了调整以使其作为启动脚本工作(它等待打开文档)。
// Set a targetengine to make this work
#targetengine "session"
function saveIDML() {
// Exit if no documents are open.
if(app.layoutWindows.length == 0) {
return;
} else {
// Get the current document
var doc = app.activeDocument;
$.writeln('Saving IDML of ' + doc + ' ...');
// Catch errors
if (!doc.saved) {
alert('Sorry, there was a problem and the document was not saved.');
exit();
}
// Create a new .idml file name from the .indd file name
var inddName = doc.name;
var idmlName = inddName.replace("indd", "idml");
// Create the new .idml file next to the .indd file
var theFile = File(File(doc.filePath).fsName + "/" + idmlName);
doc.exportFile(ExportFormat.INDESIGN_MARKUP, theFile, false);
}
}
// Listen for the save event
app.addEventListener('afterSave', saveIDML, false);
我发现@Arthur 的脚本非常有用。但是,我只想使用它afterSave
,而且afterSaveAs
(这很容易扩展:只需附加另一个事件侦听afterSaveACopy
器命令)和(我自己无法完成;我在community.adobe.com寻求帮助)。
现在我有一个适用于所有三个用例的工作脚本,见下文。
// src: https://community.adobe.com/t5/indesign/get-the-name-of-the-document-created-by-save-a-copy/m-p/10997427#M179868 (based on https://graphicdesign.stackexchange.com/a/71770, which is based on https://graphicdesign.stackexchange.com/a/71736)
// author: Fabian Morón Zirfas (fabianmoronzirfas@graphicdesign.stackexchange.com), modified by Arthur (Arthur@graphicdesign.stackexchange.com), modified by Sunil_Yadav1 (Sunil_Yadav1@community.adobe.com)
// date: 24 March 2020
// Set a targetengine to make this work
#targetengine "session"
function saveIdml() {
if(app.layoutWindows.length == 0) {
return;
} else if (! app.activeDocument.saved) {
alert('Sorry, there was a problem and the document was not saved.');
return;
}
var idmlPath = app.activeDocument.filePath.fsName.replace(/\\/g,'/') + '/' + app.activeDocument.name.replace(/\.indd|\.indt/g, '.idml');
app.activeDocument.exportFile(ExportFormat.INDESIGN_MARKUP, idmlPath, false);
}
function saveACopyIdml(e) {
var idmlPath = File(e.properties.fullName).fsName.toString().replace(/\\/g,'/').replace(/\.indd|\.indt/g, '.idml');
app.activeDocument.exportFile(ExportFormat.INDESIGN_MARKUP, idmlPath, false);
}
// Listen for the save event
app.addEventListener('afterSave', saveIdml, false);
app.addEventListener('afterSaveAs', saveIdml, false);
app.addEventListener('afterSaveACopy', saveACopyIdml, false);