Question
How to run the callback fucntion onReceive[Static+callback]-onResult-onError and sendData?
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;
}
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;
}
