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
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
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.
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
Copy link to clipboard
Copied
Thanks @Kasyan Servetsky for clarifying, I never scripted Bridge so far. @M.Hasanin 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
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 )
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
Copy link to clipboard
Copied
The send() timeout parameter also is explained here—it doesn’t pause a bridgetalk communication:
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"
}
}
Copy link to clipboard
Copied
Hi @M.Hasanin ,
Using $.sleep(milisecond) would do for you the best.
But we have to understand the purpose as well.
Best
Sunil
Copy link to clipboard
Copied
@Sunil Yadav Thanks a lot