🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.scripting.indesign
Article #1884

[CS3 JS] How to Create a Timer?

#1884
From: Eliot_Kimber
Date: Wed, 21 Jan 2009 16:06
38 lines
1888 bytes
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
Technical Details
Message-ID: <59b792d3.-1@webcrossing.la2eafNXanI>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newshub.sdsu.edu!webcrossing

Show Full Headers
Complete Article Headers
X-Google-Thread: f939a,739e585aceac2770,start
X-Google-Attributes: gidf939a,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
From: Eliot_Kimber@adobeforums.com
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newshub.sdsu.edu!webcrossing
Newsgroups: adobe.scripting.indesign
Subject: [CS3 JS] How to Create a Timer?
Message-ID: <59b792d3.-1@webcrossing.la2eafNXanI>
Date: Wed, 21 Jan 2009 08:06:48 -0800
Lines: 45
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit