0
[CS3 JS] How to Create a Timer?
New Here
,
/t5/indesign-discussions/cs3-js-how-to-create-a-timer/td-p/1125914
Jan 21, 2009
Jan 21, 2009
Copy link to clipboard
Copied
Within InDesign I need to be able to fire a periodic process to examine links from a JavaScript script. I have my own script running in its own engine.
I can't figure out how to create a timer that will run in the background and call the appropriate callback function periodically.
I've created a little process like this:
/**
* Sleeps for waitTime milliseconds then calls the callBack function.
*/
function timer(callBack, waitTime) {
$.writeln("timer(): callBack=" + callBack + ", waitTime=" + waitTime);
if (waitTime == undefined) waitTime = 2000;
$.writeln("timer(): sleeping for " + waitTime + "...");
$.sleep(waitTime);
$.writeln("timer(): awake, calling callBack");
try {
return callBack();
} catch (e) {
$.writeln("timer(): Exception from callBack.exec(): " + e);
}
return undefined;
}
function myCallBack() {
return Window.confirm("Callback called", true, "Continue looping");
}
while (true) {
if (!timer(myCallBack)) break;
}
And this works in the sense that my timer runs, but it runs as a blocking process, which is not what I want.
Is there something I'm missing or is this simply not possible in CS3 JavaScript? A search on "timer" in the InDesign forums didn't reveal anything, nor did the InDesign JavaScript Guide nor the Scripting Tools Guide.
Thanks,
Eliot
I can't figure out how to create a timer that will run in the background and call the appropriate callback function periodically.
I've created a little process like this:
/**
* Sleeps for waitTime milliseconds then calls the callBack function.
*/
function timer(callBack, waitTime) {
$.writeln("timer(): callBack=" + callBack + ", waitTime=" + waitTime);
if (waitTime == undefined) waitTime = 2000;
$.writeln("timer(): sleeping for " + waitTime + "...");
$.sleep(waitTime);
$.writeln("timer(): awake, calling callBack");
try {
return callBack();
} catch (e) {
$.writeln("timer(): Exception from callBack.exec(): " + e);
}
return undefined;
}
function myCallBack() {
return Window.confirm("Callback called", true, "Continue looping");
}
while (true) {
if (!timer(myCallBack)) break;
}
And this works in the sense that my timer runs, but it runs as a blocking process, which is not what I want.
Is there something I'm missing or is this simply not possible in CS3 JavaScript? A search on "timer" in the InDesign forums didn't reveal anything, nor did the InDesign JavaScript Guide nor the Scripting Tools Guide.
Thanks,
Eliot
TOPICS
Scripting
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Participant
,
/t5/indesign-discussions/cs3-js-how-to-create-a-timer/m-p/1125915#M367652
Jan 21, 2009
Jan 21, 2009
Copy link to clipboard
Copied
It's not possible in JavaScript. You could use a platform-dependent scripting language to do the job and have it call the JavaScript.
You could attach your script to a suitable selection of menuActions so that the user unknowingly triggers your script each time he uses any of the menuActions.
Ideally, an idle message would be used so that the script runs when the user isn't doing anything (as opposed to when he is) but I don't think such a thing is accessible to JavaScript.
Dave
You could attach your script to a suitable selection of menuActions so that the user unknowingly triggers your script each time he uses any of the menuActions.
Ideally, an idle message would be used so that the script runs when the user isn't doing anything (as opposed to when he is) but I don't think such a thing is accessible to JavaScript.
Dave
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Explorer
,
/t5/indesign-discussions/cs3-js-how-to-create-a-timer/m-p/1125917#M367654
Jan 21, 2009
Jan 21, 2009
Copy link to clipboard
Copied
Dave_Saunders@adobeforums.com wrote:
> It's not possible in JavaScript. You could use a platform-dependent scripting language to do the job and have it call the JavaScript.
>
It may be possible if the timer is in a separate engine or actually running in
Bridge. You would have to use BridgeTalk and make synchronous calls to the
callback object, but it may get you what you want.
Interesting problem. Please let us know how it turns out.
-X
> It's not possible in JavaScript. You could use a platform-dependent scripting language to do the job and have it call the JavaScript.
>
It may be possible if the timer is in a separate engine or actually running in
Bridge. You would have to use BridgeTalk and make synchronous calls to the
callback object, but it may get you what you want.
Interesting problem. Please let us know how it turns out.
-X
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
ekimber
AUTHOR
New Here
,
/t5/indesign-discussions/cs3-js-how-to-create-a-timer/m-p/1125916#M367653
Jan 21, 2009
Jan 21, 2009
Copy link to clipboard
Copied
OK--it helps to know it's not possible. I can try the platform-specific route.
Thanks,
Eliot
Thanks,
Eliot
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

/t5/indesign-discussions/cs3-js-how-to-create-a-timer/m-p/1125918#M367655
Jan 21, 2009
Jan 21, 2009
Copy link to clipboard
Copied
I keep asking for app.scheduleTask in InDesign. It's an extremely handy utility.
APID has such a feature, you can use that as well.
Bob
APID has such a feature, you can use that as well.
Bob
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Valorous Hero
,
/t5/indesign-discussions/cs3-js-how-to-create-a-timer/m-p/1125919#M367656
Jan 21, 2009
Jan 21, 2009
Copy link to clipboard
Copied
Hi Eliot,
Have a look at this thread: http://www.adobeforums.com/webx?128@@.59b6d3d2
Kasyan
Have a look at this thread: http://www.adobeforums.com/webx?128@@.59b6d3d2
Kasyan
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
ekimber
AUTHOR
New Here
,
/t5/indesign-discussions/cs3-js-how-to-create-a-timer/m-p/1125920#M367657
Jan 21, 2009
Jan 21, 2009
Copy link to clipboard
Copied
Hmm, I must have missed that thread when I initially searched on "timer" across the InDesign forums.
The "idle" event technique looks like just what I want.
Thanks,
Eliot
The "idle" event technique looks like just what I want.
Thanks,
Eliot
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Valorous Hero
,
/t5/indesign-discussions/cs3-js-how-to-create-a-timer/m-p/1125921#M367658
Jan 21, 2009
Jan 21, 2009
Copy link to clipboard
Copied
When I wrote a JS script using idle event I encountered a problem: it worked, but the cursor was blinking annoyingly. So, I think it’s better to make a stay-open AS script if you are on Mac, or use VB’s Timer object if you are on PC.
Kasyan
Kasyan
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Valorous Hero
,
/t5/indesign-discussions/cs3-js-how-to-create-a-timer/m-p/1125922#M367659
Jan 21, 2009
Jan 21, 2009
Copy link to clipboard
Copied
Eliot,
To illustrate what I mean here is an example:
Create a controller and attach this script to it, set Event Filter to 'idle'.
Kasyan
To illustrate what I mean here is an example:
Create a controller and attach this script to it, set Event Filter to 'idle'.
if (theItem.dataStore > 10){
doSomething();
theItem.dataStore = 0;
}
else
{
theItem.dataStore = theItem.dataStore + 1;
}
function doSomething(){
alert("Time is up.");
}
Kasyan
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
ekimber
AUTHOR
New Here
,
/t5/indesign-discussions/cs3-js-how-to-create-a-timer/m-p/1125923#M367660
Jan 21, 2009
Jan 21, 2009
Copy link to clipboard
Copied
I'm not sure what you mean by "create a controller"--can you point me to the relevant docs?
Thanks,
Eliot
Thanks,
Eliot
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
New Here
,
/t5/indesign-discussions/cs3-js-how-to-create-a-timer/m-p/1125924#M367661
Jan 21, 2009
Jan 21, 2009
Copy link to clipboard
Copied
A flash movie could implement such a timer. You show that in ScriptUI and let it trigger the JS via the same mechanisms as used by PatchPanel.
http://labs.adobe.com/wiki/index.php/PatchPanel
Dirk
http://labs.adobe.com/wiki/index.php/PatchPanel
Dirk
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Valorous Hero
,
LATEST
/t5/indesign-discussions/cs3-js-how-to-create-a-timer/m-p/1125925#M367663
Jan 21, 2009
Jan 21, 2009
Copy link to clipboard
Copied
1. Download and install Active Page Item Developer Toolkit.
http://www.rorohiko.com/wordpress/indesign-downloads/active-page-item-developer/
You'll have a demo period for 20 days or a month, I don't remember exactly.
2. Create a new document, open 'Active Page Item Developer' panel (Windows menu).
3. Copy the script from my previous post, draw an object - e.g. a rectangle and with the object selected enter 'idle' into Event Filter field, then press Tab and paste the script into the largest field.
You'll see an alert appearing every 10 seconds and the cursor flickering.
http://www.rorohiko.com/wordpress/indesign-downloads/active-page-item-developer/
You'll have a demo period for 20 days or a month, I don't remember exactly.
2. Create a new document, open 'Active Page Item Developer' panel (Windows menu).
3. Copy the script from my previous post, draw an object - e.g. a rectangle and with the object selected enter 'idle' into Event Filter field, then press Tab and paste the script into the largest field.
You'll see an alert appearing every 10 seconds and the cursor flickering.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

