Skip to main content
M.Hasanin
Inspiring
August 27, 2021
Question

What the Difference Between Send() and Sleep() ? and Which Better to Delay Script a little ?

  • August 27, 2021
  • 4 replies
  • 1158 views

Hi Experts

What the Difference Between Send() and Sleep() ? and Which Better to Delay Script a little ? and What the best practice to Delay a loop a little? and Thanks in Advance

This topic has been closed for replies.

4 replies

Sunil Yadav
Brainiac
September 3, 2021

Hi @M.Hasanin ,

Using $.sleep(milisecond) would do for you the best.

But we have to understand the purpose as well.

 

Best

Sunil

M.Hasanin
M.HasaninAuthor
Inspiring
September 17, 2021

@Sunil Yadav Thanks a lot

BestMohammad Hasanin
rob day
Community Expert
August 29, 2021

The send() timeout parameter also is explained here—it doesn’t pause a bridgetalk communication:

 

https://extendscript.docsforadobe.dev/interapplication-communication/communicating-through-messages.html

 

Here’s another example which generates alerts from both InDesign and Photoshop where I’m creating a new Photoshop document from an InDesign script—bt.send(10) doesn’t pause the script as @Kasyan Servetsky explained, it’s a timeout in case the Photoshop function takes too long to execute :

 

 

 

//InDesign as the script application
#target indesign
#targetengine "session" 

var n = "My PS Doc"
makeNewPhotoshopDoc(n);

/**
* Opens Photoshop and runs psScript 
*  value void
* 
*/
function makeNewPhotoshopDoc(n){
    //open Photoshop and run psScript
    var bt = new BridgeTalk();  
    bt.target = "photoshop";  
    bt.body = "var n = '"+n+"';" 
    //the function and the call
    bt.body += psScript.toString() + "psScript();";

    bt.onResult = function(resObj) { 
        alert(resObj.body);
    }  
    bt.onError = function( inBT ) { alert(inBT.body); };  
    bt.send(10);  
      
    function psScript() {  
        alert("Photoshop Running, making new document")
        var doc = app.documents.add(5, 5, 300.0, n);
        doc.name = n
    
        return "InDesign running, message returned from Photoshop: New Document named " +n+ " complete"
    }  
}

 

 

 

 

Kasyan Servetsky
Brainiac
August 28, 2021

send() is used in BridgeTalk -- which is used to make a script to talk between different adobe apps like InDesign, Photoshop, Illustrator, Bridge in JavaScript.

timoutInSecs -- is an optional parameter: "A maximum number of seconds to wait for a result before returning from this function. The message is sent synchronously, and the function does not return until the target has processed the message or this number of seconds has passed." (quote from the JS tools guide)

In my experience, (I don't remember all details at the moment so may be wrong) you need to set it to some value, e.g. send(100) if you want to get back a result from the BridgeTalk message. It makes no noticeable delay in the script execution. For details, read here the post written by Bob Stucky (the best explanation on the topic!).

Sleep() -- Suspends the calling thread for the given number of milliseconds.

As far as I understand, it pauses script execution. However, I've never used it in my scripting practice.

 

M.Hasanin
M.HasaninAuthor
Inspiring
August 28, 2021

Thanks a lot @Kasyan Servetsky  for Details Explains, I Learned new skill today

Thank you @Manan Joshi for being interested, actually i read the post in a hurry here but i miss understand, i thought it will work in InDesign , the Post also Answered By @Kasyan Servetsky 

here :

https://community.adobe.com/t5/indesign/removing-sleep-in-code/m-p/2283023#M261699 

BestMohammad Hasanin
Community Expert
August 28, 2021

What is the Send method, I can't recall using it or did find anything in the object model. Could you please describe where you found this method.

-Manan