我有这个保存文件副本的JavaScript。我需要它在每次打开文件时自动运行,并将该副本保存到特定文件夹。这就是我到目前为止所拥有的:
var myDoc = app.activeDocument;
myDoc.save();
var myFile = myDoc.fullName;
var myDate = new Date;
var mySuffix = "_Backup_" + myDate.getDate() + "_" + myDate.getMonth() + "_" + myDate.getHours() + "-" + myDate.getMinutes() + "-" + myDate.getSeconds() +".indd"
var myBaseName = myDoc.fullName.fsName.match(/(.*)\.[^\.]+$/)[1] ;
var myNewFile = new File(myBaseName + mySuffix);
myFile.copy(myNewFile);
答案 0 :(得分:2)
所以你想要的是一个事件监听器。 (请参阅InDesign scripting guide中的“使用事件监听器”部分。)
将.jsx文件保存在“启动脚本”文件夹中。 (在Mac上,它位于/ Applications / Adobe InDesign CS6 / Scripts / startup scripts /.)
#targetengine "session"
app.addEventListener('afterOpen', function(myEvent) {
// afterOpen fires twice: once when the document opens
// and once when the window loads. Choose one,
// ignore the other.
// See: http://forums.adobe.com/message/5410190
if (myEvent.target.constructor.name !== 'Document') {
return;
}
var myDoc = myEvent.target;
// Continue on with your code from here
}