BridgeTalk Callback?

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

Wolf_22
Posts: 14
Joined: Tue Nov 24, 2020 7:00 pm

BridgeTalk Callback?

Post by Wolf_22 »

I'm trying to illicit ESTK console output from a BridgeTalk callback, but it never seems to work.

Here's my script:

Code: Select all

var bt = new BridgeTalk();
bt.target = 'estoolkit-4.0';
bt.body = function(){
	app.clc();//Clears console.
}.toSource()+"()";

bt.onResult = function( responseMsgObject ) {
	$.writeln(responseMsgObject.body);//Why isn't the callback working?
	debugger;
};
Simply put, the main goal I had with this was to use scripting to clear the console. This seems to work... But I thought I'd see what a response looks like by implementing the onResult callback, which never seems to fire off. Testing functionality within ESTK can sure be hit-and-miss at times, but as of right now, whenever I run the following...

Code: Select all

$.writeln(bt.sendResult());
...the console says TRUE. So shouldn't the onResult callback work?

Any insight into this would be appreciated.
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: BridgeTalk Callback?

Post by Kukurykus »

Remove: //Clears console.
And add at end: bt.send()

Ps. I never used debugger and sendResult(), so I'd like to see some working examples of it, something better that's in 'JAVASCRIPT TOOLS GUIDE'.
Wolf_22
Posts: 14
Joined: Tue Nov 24, 2020 7:00 pm

Re: BridgeTalk Callback?

Post by Wolf_22 »

Sorry about that, Kukurykus. I feel like an idiot because I actually had that in my code (in ESTK) but I messed up by not selecting it when I was copying-and-pasting everything into my post on here. But it was in there and it still wasn't working.

Here's my complete code since my original post but the callbacks just never work for some reason (the alert never shows anything, the console never prints anything, and the debugger never pauses the run):

Code: Select all

var bt = new BridgeTalk();
bt.target = 'estoolkit-4.0';
bt.body = function(){
	app.clc();
}.toSource()+"()";
bt.onResult = function( responseMsgObject ) {
	alert('test1');
	$.writeln(responseMsgObject.body);
	debugger;
};
bt.onError = function (btObj) {
	alert('test2');
	var errorCode = parseInt (btObj.headers ["Error-Code"]);
	throw new Error (errorCode, btObj.body);
}
bt.send();
Examples would be a good thing to have for all of this. Diving into ExtendScript using the ESTK has been like pulling teeth for me. I'm not sure about you but I know that with my experiences, it never seems like you can depend on the Data Browser information. Granted, I just upgraded it to version 4.0 yesterday, so maybe things will be better but considering I'm trying to use it for developing against CS:3, I'm not holding my breath. And I'm with you about that guide... I mean, that thing helps but like you said, the examples are so sparse and limited that it leaves plenty of room for improvement.
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: BridgeTalk Callback?

Post by Kukurykus »

For me it works. I see 'test1' in alert, and true in console, also when I use number 1 or higher in bt.send(), debugger activates.
Wolf_22
Posts: 14
Joined: Tue Nov 24, 2020 7:00 pm

Re: BridgeTalk Callback?

Post by Wolf_22 »

Kukurykus, I think it was the bt.send() parameter being omitted that was causing me headaches as doing what you did (and passing in 1) finally got the function to trigger.

This is frustrating because the page I used to understand how to use the send() function (found here: https://extendscript.docsforadobe.dev/i ... =send#send) comes across as if omitting the "timeoutInSecs" parameter would result in the function returning immediately (but makes no implication about how that can apparently cause functionality problems).

Thanks for helping me out with this. It means a lot. :)
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: BridgeTalk Callback?

Post by Kukurykus »

It doesn't make functionality problems. You use bt.send() without parameter when you send message without awaiting callback.
Wolf_22
Posts: 14
Joined: Tue Nov 24, 2020 7:00 pm

Re: BridgeTalk Callback?

Post by Wolf_22 »

Completely true, Kukurykus. Just wanted to blame something besides myself. ;)