質問

I have this javascript that saves a copy of a file. I need it to run automatically every time a file is opened and also save that copy to a specific folder. Here's what I have so far:

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);
役に立ちましたか?

解決

So what you want is called an event listener. (See the section "Working with event listeners" in the InDesign scripting guide.)

Save your .jsx file in the "startup scripts" folder. (On a Mac, it's in /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
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top