Is there an equivalent of setTimeout in Adobe's ExtendScript

Shawn picture Shawn · May 22, 2012 · Viewed 8.7k times · Source

Javascript's setTimeout function is a method of the window object. This object doesn't exist in ExtendScript and is therefore not available to scripts made for Adobe InDesign or Illustrator. What can I use instead to acheive the same results?

Answer

pdizz picture pdizz · May 22, 2012

It's part of the extendscript's $ object.

$.sleep(1000) //tell extendscript to sleep 1000 milliseconds

Not the same as setTimeout() but you should be able to make it work for you.

EDIT: Here is setTimeout extension for extendscript:

$.setTimeout = function(func, time) {
        $.sleep(time);
        func();
};

$.setTimeout(function () {alert("hello world")}, 3000);