Adobe 0046100128056 Scripting Guide - Page 125
property of the idle task is the amount of time that elapses before InDesign calls the task again.
UPC - 718659087562
View all Adobe 0046100128056 manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 125 highlights
CHAPTER 8: Events Sample onIdle Event Listener 125 can be used to automatically execute a script when InDesign/InCopy is idle. Its event target is IdleTask, and its event object is IdleEvent. The sleep property of the idle task is the amount of time that elapses before InDesign calls the task again. It should be obvious that you need to set the sleep time to a value high enough that it does not interfere with your work, though this value will vary depending on what tasks the script performs. Setting the sleep time to zero deletes the task (though it does not remove the event listener). This is the most convenient way to stop an idle task. The following script shows how to add an eventListener and show a message box from the idle task (for the complete script, see Reminder): #targetengine "session" main(); function main() { var myIdleTask = app.idleTasks.add({name:"my_idle_task", sleep:10000}); var onIdleEventListener = myIdleTask.addEventListener(IdleEvent.ON_IDLE, onIdleEventHandler, false); alert("Created idle task " + myIdleTask.name + "; added event listener on " + onIdleEventListener.eventType); } function onIdleEventHandler(myIdleEvent) { if (app.documents.length == 0) { var myDoc = app.documents.add(); alert("Created document " + myDoc.name + " in idle task."); return; } var myTextFrames = app.activeDocument.pages.item(0).textFrames; if (myTextFrames.length == 0) { var myTextFrame = myTextFrames.add(); myTextFrame.geometricBounds = ["72pt", "72pt", "288pt", "288pt"]; myTextFrame.contents = "Text frame created in idle task"; alert("Created a text frame in idle task."); return; } //Delete idle task by setting its sleep time to zero. myIdleEvent.parent.sleep = 0; alert("Nothing to do. Delete idle task."); } To remove the idle task created by preceding script, run the following script (for the complete script, see RemoveIdleTask):