🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: adobe.scripting.indesign
12 messages
12 total messages Started by Eliot_Kimber Wed, 21 Jan 2009 16:06
[CS3 JS] How to Create a Timer?
#1884
Author: 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
Re: [CS3 JS] How to Create a Timer?
#1885
Author: Dave_Saunders
Date: Wed, 21 Jan 2009 16:28
7 lines
1091 bytes
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
Re: [CS3 JS] How to Create a Timer?
#1886
Author: Eliot_Kimber
Date: Wed, 21 Jan 2009 16:52
5 lines
680 bytes
OK--it helps to know it's not possible. I can try the platform-specific route.

Thanks,

Eliot
Re: [CS3 JS] How to Create a Timer?
#1887
Author: xbytor
Date: Wed, 21 Jan 2009 16:54
11 lines
1150 bytes
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
Re: [CS3 JS] How to Create a Timer?
#1888
Author: Bob Stucky
Date: Wed, 21 Jan 2009 16:55
5 lines
745 bytes
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
Re: [CS3 JS] How to Create a Timer?
#1890
Author: Kasyan Servetsky
Date: Wed, 21 Jan 2009 16:59
5 lines
705 bytes
Hi Eliot,

Have a look this thread: <http://www.adobeforums.com/webx?128@@.59b6d3d2>

Kasyan
Re: [CS3 JS] How to Create a Timer?
#1891
Author: Eliot_Kimber
Date: Wed, 21 Jan 2009 17:27
7 lines
776 bytes
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
Re: [CS3 JS] How to Create a Timer?
#1949
Author: Kasyan Servetsky
Date: Wed, 21 Jan 2009 19:07
3 lines
866 bytes
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&#8217;s better to make a stay-open AS script if you are on Mac, or use VB&#8217;s Timer object if you are on PC.

Kasyan
Re: [CS3 JS] How to Create a Timer?
#1950
Author: Kasyan Servetsky
Date: Wed, 21 Jan 2009 19:26
23 lines
1029 bytes
Eliot,

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
Re: [CS3 JS] How to Create a Timer?
#1952
Author: Eliot_Kimber
Date: Wed, 21 Jan 2009 20:15
5 lines
693 bytes
I'm not sure what you mean by "create a controller"--can you point me to the relevant docs?

Thanks,

Eliot
Re: [CS3 JS] How to Create a Timer?
#1955
Author: Dirk.Becker
Date: Wed, 21 Jan 2009 23:10
5 lines
813 bytes
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
Re: [CS3 JS] How to Create a Timer?
#1960
Author: Kasyan Servetsky
Date: Thu, 22 Jan 2009 07:35
9 lines
1185 bytes
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.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads