【问题标题】:Need InDesign script to run on file open需要 InDesign 脚本在文件打开时运行
【发布时间】:2014-04-23 21:31:16
【问题描述】:
我有这个保存文件副本的 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);
【问题讨论】:
标签:
javascript
adobe
adobe-indesign
【解决方案1】:
所以你想要的是一个事件监听器。 (请参阅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
}