Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

[CS3 JS] How to Create a Timer?

New Here ,
Jan 21, 2009 Jan 21, 2009
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
TOPICS
Scripting
2.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 21, 2009 Jan 21, 2009
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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 21, 2009 Jan 21, 2009
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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 21, 2009 Jan 21, 2009
OK--it helps to know it's not possible. I can try the platform-specific route.

Thanks,

Eliot
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 21, 2009 Jan 21, 2009
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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Jan 21, 2009 Jan 21, 2009
Hi Eliot,

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

Kasyan
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 21, 2009 Jan 21, 2009
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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Jan 21, 2009 Jan 21, 2009
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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Jan 21, 2009 Jan 21, 2009
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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 21, 2009 Jan 21, 2009
I'm not sure what you mean by "create a controller"--can you point me to the relevant docs?

Thanks,

Eliot
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 21, 2009 Jan 21, 2009
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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Jan 21, 2009 Jan 21, 2009
LATEST
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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines