Skip to main content
Brian_Raila
Inspiring
February 20, 2020
Answered

Using setTimeOut, setInterval, or other means, to delay script execution

  • February 20, 2020
  • 1 reply
  • 7150 views

 

I have previously posted my Big Picture objective.  Here, I take a Big Step Back, to get a grip on this, in the simplest context I can think of [welcome advice from (try67)].  But I am hindered by perilous partial-understanding of scripting [enough rope to...].

 

I've reviewed the JavaScriptTM for Acrobat® API Reference.  I've scoured online references/suggestions/examples.  I've created a slew of test documents.  Almost without exception, they function 'dead in the water.'  I am missing some things basic, and fundamental.

 

I sense I get hung up on [despite awareness of need for precision]

  • distinguishing Acrobat-oriented JavaScript from HTML/browser-oriented use
  • syntax precision -- e.g. case sensitivity, quotation-marks-or-not, ...
  • app-level [Acrobat] vs. document-level vs. page-level management

 

I've considered setTimeOut, and setInterval, all sorts of ways.  Here's what seems the simplest case [courtesy Thom Parker, 2008].  Upon a Button Event:

 

app.alert("Hello World", 3);

 

This works, as seen in the attachment.

 

But then, on a separate Buttion, I try to trigger the Alert as a parameter of setTimeOut:

 

// Utilize setTimeout ( expression, timeout );
//where expression is the JavaScript code to run after timeout milliseconds have elapsed.
//
setTimeout (app.alert("Hello World", 3), 2000 );

 

This fails, as seen in the attachment.

 

I can readily imagine that an entirely different approach is called for.  But I am at a loss for insight/instinct as to whether this demands a defined routine/function/variables/declarations, etc., in what order, etc.  I bet a number of you can see, at a glance, where I'm way off base.

 

Commentary most appreciated.

 

Correct answer Thom Parker

 

app.setTimeOut ('app.alert("Hello World", 3)', 2000 );

 

 

The script input is a string. And "setTimeOut" is a member of the app object. And the "O" in "out" is capitalized. 

JavaScript is case sensitive. You must use the functions in the correct context and verbatim.

Here's the reference entry, Use It:

https://help.adobe.com/en_US/acrobat/acrobat_dc_sdk/2015/HTMLHelp/#t=Acro12_MasterBook%2FJS_API_AcroJS%2Fapp_methods.htm%23TOC_setTimeOutbc-35&rhtocid=_6_1_8_6_1_34

 

 

 

 

1 reply

Thom Parker
Community Expert
Thom ParkerCommunity ExpertCorrect answer
Community Expert
February 20, 2020

 

app.setTimeOut ('app.alert("Hello World", 3)', 2000 );

 

 

The script input is a string. And "setTimeOut" is a member of the app object. And the "O" in "out" is capitalized. 

JavaScript is case sensitive. You must use the functions in the correct context and verbatim.

Here's the reference entry, Use It:

https://help.adobe.com/en_US/acrobat/acrobat_dc_sdk/2015/HTMLHelp/#t=Acro12_MasterBook%2FJS_API_AcroJS%2Fapp_methods.htm%23TOC_setTimeOutbc-35&rhtocid=_6_1_8_6_1_34

 

 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Brian_Raila
Inspiring
February 20, 2020

I told you, you'd know at a glance!

 

Thanks, Thom.

Thom Parker
Community Expert
Community Expert
February 20, 2020

Note that I updated my post with the correct syntax.

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often