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

Enthusiast ,
Aug 27, 2021 Aug 27, 2021

Copy link to clipboard

Copied

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

Best
M.Hasanain
TOPICS
Scripting

Views

165

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Aug 27, 2021 Aug 27, 2021

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

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
Guru ,
Aug 28, 2021 Aug 28, 2021

Copy link to clipboard

Copied

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.

 

Likes

Translate

Translate

Report

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
Enthusiast ,
Aug 28, 2021 Aug 28, 2021

Copy link to clipboard

Copied

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 

Best
M.Hasanain

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Aug 28, 2021 Aug 28, 2021

Copy link to clipboard

Copied

Thanks @Kasyan Servetsky for clarifying, I never scripted Bridge so far. @M.Hasanain from what i read that Kasyan shared I feel the obvious choice for you would be send method if you are indeed sending the call to another host application. So in general I would say send is a specialised method created for a specific purpose while sleep is a generic method that works via timely polling. You can play around to see what suits you best but for your use case.

-Manan

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Aug 31, 2021 Aug 31, 2021

Copy link to clipboard

Copied

Hi Manan,

it's not about scripting Adobe Bridge, the application.

BridgeTalk is an ExtendScript module to bridge the gap between applications like InDesign, PhotoShop, Illustrator and others. You can talk to PhotoShop using a script for InDesign for example…

 

Regards,
Uwe Laubender

( ACP )

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Aug 31, 2021 Aug 31, 2021

Copy link to clipboard

Copied

Thanks @Laubender for adding context. I am sorry that I did not choose the right words to explain it better, I did actually mean what you so kindly explained. Sadly I have not worked on a script that needed inter application interactions so BridgeTalk was never used, so I am majorly ignorant on this aspect of scripting

-Manan

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Aug 29, 2021 Aug 29, 2021

Copy link to clipboard

Copied

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

 

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

 

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"
    }  
}

 

 

 

 

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Sep 02, 2021 Sep 02, 2021

Copy link to clipboard

Copied

Hi @M.Hasanain ,

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

But we have to understand the purpose as well.

 

Best

Sunil

Likes

Translate

Translate

Report

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
Enthusiast ,
Sep 17, 2021 Sep 17, 2021

Copy link to clipboard

Copied

LATEST

@Sunil Yadav Thanks a lot

Best
M.Hasanain

Likes

Translate

Translate

Report

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