Skip to main content
Known Participant
November 4, 2005
Question

How to run the callback fucntion onReceive[Static+callback]-onResult-onError and sendData?

  • November 4, 2005
  • 20 replies
  • 2818 views
Hi, everybody,
I can run this script in indesign cs2 very well,
But now I went to get the target running script is OK or No, and When it completed,
Now I would like those info. send back to the sender, then do some otherthings.
So, help me how to get those infors, include the errorMsg.

Thanks advanced!

jxswm

//=======================================================

//RunScript
//Usage:
//Define the scriptEnum and runTargetScript(scriptEnum), all is OK!
//Set the scriptEnum.scriptStr = null, will do not run the ScriptString;
//Set the scriptEnum.fileURI = null, will do not run the ScriptFile;
//Set the scriptEnum.isRunTargetApp = true, will run the target program before run the script;
//Set the scriptEnum.isBringToFront = false, will not bring the target program 's main window
//is not brought to the front of the screen.
//eg:
//In indesign CS2, run below script, you can see the result

do{
var scriptEnum = {};
scriptEnum.senderAppName = "indesign";
scriptEnum.targetAppName = "bridge";//"illustrator";//"photoshop";//"bridge"
scriptEnum.isRunTargetApp = true;
scriptEnum.isBringToFront = true;
scriptEnum.fileURI = null;//"D:\\Adobe\\Adobe Indesign CS2\\Presets\\Scripts\\File+Folder\\00)FilesReport.js";
scriptEnum.scriptStr =
"alert(\"Hellow World! From " + scriptEnum.senderAppName + "-> " + scriptEnum.targetAppName + "\");\n"+
"var result = {}; \n"+
"result.file = new File(\"c:\\1.jpg\");\n"+
"result.toSource();";

if(!validateSenderScriptVersion(scriptEnum)){break;}
#target indesign

if(!runScript(scriptEnum)){
alert("Run the script failure!");
break;
}
}while(false);

function validateSenderScriptVersion(scriptEnum){
switch(scriptEnum.senderAppName){
case "indesign": return app.version != 3; break;
default: break;
}
return false;
}

function runScript(scriptEnum){
if(BridgeTalk.appName != scriptEnum.senderAppName ){return false;}
var targetAppName = scriptEnum.targetAppName;
if(!BridgeTalk.getSpecifier(targetAppName)){return false;}
if(scriptEnum.isRunTargetApp){
if(!BridgeTalk.isRunning(targetAppName)){
var runtime = 0;
var totalDelayTime = 180*1000;
var periodDelyTime = 3*1000;
if(scriptEnum.isBringToFront){
if(BridgeTalk.launch(targetAppName)){
//There might be a queued for sending later for still not run the target app,
//so wait it 15s until the target app run completly.
//if(delayTime(180*1000, 3*1000, !BridgeTalk.isRunning(targetAppName))){return false;}
while(totalDelayTime > runtime && !BridgeTalk.isRunning(targetAppName)){
$.sleep(periodDelyTime);
runtime += periodDelyTime;
}
if(!BridgeTalk.isRunning(targetAppName)){return false;}
}else{return false;}
}else{
if(BridgeTalk.launch(targetAppName, "background")){
while(totalDelayTime > runtime && !BridgeTalk.isRunning(targetAppName)){
$.sleep(periodDelyTime);
runtime += periodDelyTime;
}
if(!BridgeTalk.isRunning(targetAppName)){return false;}
}else{return false;}
}
}
}
var sStr = scriptEnum.scriptStr;
if(!sStr || sStr == ""){sStr = load(scriptEnum.fileURI);}
if(!sStr || sStr == ""){return false;}
if(!runScriptAString(sStr, targetAppName, scriptEnum.isBringToFront)){
return false;
}
return true;
}
This topic has been closed for replies.

20 replies

Known Participant
November 23, 2005
Andrew,

BridgeTalk.bringToFront('bridge');

worked as advertised. I had tried it before and had a problem - don't know why.

Anyway, thanks agian for the help.

Regards
Rory
Known Participant
November 22, 2005
Thanks Andrew, I'll give that a try.

Rory
Known Participant
November 22, 2005
Try

BridgeTalk.bringToFront ('bridge');

In the PS script where you want Bridge brought back in front.

So, for example, where I was wrapping a 'theScript' PS Script string up in a function and then sending it off to Photoshop along the lines of Bob's Open/Close script I used:

function ah_wrapScriptBTF (theScript,ah_DataArString) {
return "ah_RunWrappedScript('"+ah_DataArString+"');function ah_RunWrappedScript(ah_DataArString){"+theScript+"};BridgeTalk.bringToFront ('bridge');";
}

Andrew
Known Participant
November 22, 2005
I have implemented Bob's FileIterator script to run a photoshop remotre script and I have added the progressDialog to show progress, file by file. This works great except when bridge has to open photoshop at the start of bt.send().

When this happens, photoshop becomes the front window and the bridge progress dialog is no longer visible. How to I execute a bridge bringToFront from the remote script after photoshop opens?

Rory
_jxswm_Author
Known Participant
November 9, 2005
I am wrong, it works.

I forgot to change onResult's target = "indesign".

Thanks.
_jxswm_Author
Known Participant
November 9, 2005
hi, Bob,

Just now I test this process. When I using bridge-->ID, the script can process ONLY one indd file(all files certainly is ".indd"), but in Bridge --> PS, all the listed files(".jpg") can processed.
This is a strange thing.

this is the ID script:
FileIterator.remoteScript = function( file ) {
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.neverInteract;
var doc = app.open(file);
doc.close();
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
}

Can test it?

Thanks.

jxswm
Known Participant
November 9, 2005
Since it seems that running it from ID might be a problem, I was suggesting a solution that would work for certain.

And then you get the added benefit of being able to select more than one ID file and process them sequentially.

I assume the call to open a given file in ID and extract the image File object will not take all that long. So while it is less efficient, not alarmingly so. Especially when you said that the files contain some 500 images to be processed.

Bob
_jxswm_Author
Known Participant
November 9, 2005
Bob,

Following the process command you listed, it will work, but the efficiency will be very lower than from ID directly to PS.

Why can not directly RUN from ID--->PS?

jxswm
Known Participant
November 8, 2005
jxswm,

Hang on. My ID skills are lacking... I am asking an ID expert to chip in.

You may want to consider executing this from bridge (where we know it works!).

The process would be:

1. Get selected files in Bridge (the ID files)

2. Send a script to ID to open the file, extract the filenames to process, return those to Bridge.

3. Send a script to PS to process the images

4. Send a script back to ID with the filenames to re-link

5. Save and close the ID file, open the next ID file.

Bob
_jxswm_Author
Known Participant
November 8, 2005
hi,Bob,

Than you very much!

Now I can understand the whole process and make it can run in Est -> ps and bridge -> ps, it very nice, but I can not succeed in ID-->PS, it generate a Error, tell me the Indesign 4.0.jsx file in the startscript folder---initialData Timeout, then my Indesign prompt a error msg: Indesign meet a serious error...
I click the "OK" button, the ID quit.
I have test it several times and get the same result.

Why I get the Error?
And I run this script will concact the "Indesign 4.0.jsx",why?
And get the initialData---Timeout, How to do?

BTW:
I use the VBA can get this similar process and run good.
But I would like to use Bridge to do this work, because I would make it sucess in Apple OS.

I am very pleasure to try and make it can help my work under your very kindly and friendly help!..

Thank you very much!
And how to do next?

jxswm

Thanks.