javascript - Need InDesign script to run on file open -
I have this javascript which saves a copy of a file. I need that whenever a file is opened, it automatically runs and saves that copy in a specific folder. Here's what I've done 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 () + ".index" mybaseName = myDoc.fullName.fsName.match (/ (. *) \. [^ \.] + $ /) [1]; Var myNewFile = new file (myBaseName + mySuffix); myFile.copy (myNewFile);
Therefore what you want is called an event listener. (See the "Working with Event Listener" section.)
Save your .jsx file to the "Startup Script" folder. (On a Mac, this is the / application / Adobe InDesign CS6 / script / startup script /.) / P>
#targetengine "session" app.addEventListener ('afterOpen', function (myEvent) {/ Fire twice after: Once the document window opens, and once the window is loaded, choose one, // ignore the other. See: http://forums.adobe.com/message/5410190 if ( MyEvent.target .constructor.name! == 'document') {return;} var myDoc = myEvent.target; // continue with your code here)
Comments
Post a Comment