Copy link to clipboard
Copied
I'm trying to send a folder path from InDesign to another Adobe apps, like Illustrator and Photoshop, but it's not working. What am I doing wrong?
The variable tempFolder is app.activeDocument.filePath;
var bt = new BridgeTalk();
bt.target = "photoshop";
var str = ("var tempFolder = " + tempFolder.toSource() + ";");
bt.body = str;
bt.onError = function (e) { alert("Error: " + e); }
bt.onResult = function (res) { alert(res); };
bt.send();
In this particular example, Photoshop does nothing.
If I change the var str to ("alert(\"Any message\")"); it works.
Thanks in advance.
Try something like this:
//InDesign as the script application
//#target indesign
#targetengine "session"
/**
* Bridgetalk function
* param the string variable
*
*/
runPhotoshop(Folder.desktop);
/**
* Run function in ID after BT function is completed
* param the string or object returned from Photoshop
*
*/
function runID(s){
alert("InDesign running string returned from Photoshop: " + s)
}
/**
* Opens Photoshop via Bridgetalk and runs psScript
* param the string or object se
...
Copy link to clipboard
Copied
Try something like this:
//InDesign as the script application
//#target indesign
#targetengine "session"
/**
* Bridgetalk function
* param the string variable
*
*/
runPhotoshop(Folder.desktop);
/**
* Run function in ID after BT function is completed
* param the string or object returned from Photoshop
*
*/
function runID(s){
alert("InDesign running string returned from Photoshop: " + s)
}
/**
* Opens Photoshop via Bridgetalk and runs psScript
* param the string or object sent to Photoshop
*
*/
function runPhotoshop(f){
//open Photoshop and run psScript() function
var bt = new BridgeTalk();
bt.target = "photoshop";
//a string representaion of variables and the function to run.
//a string var. Note string single, double quote syntax '"+s+"'
bt.body = "var tempFolder = '"+f+"';"
//the function and the call
bt.body += psScript.toString() + "psScript();";
$.writeln(bt.body)
bt.onResult = function(resObj) {
runID(resObj.body)
}
bt.onError = function( inBT ) { alert(inBT.body); };
bt.send(8);
function psScript() {
alert("Photoshop is running, tempFolder = " + tempFolder)
return tempFolder
}
}
Copy link to clipboard
Copied
Thank you so much, Rob.
Some changes here and there. Some adaptation here and there...
And I am able to make this work.
But I needed some workarounds in, for example, stringValue.split("\r") or stringValue.split(/[\r\n]/).
Besides that, your help was the key I was looking for. Thanks again!
Copy link to clipboard
Copied
This is the template I use for passing in different types—string, array, number, object:
//InDesign as the script application
//#target indesign
#targetengine "session"
var arr = [true, "Hello", 50];
var obj = {h:350, w:500}
//Run a BridgeTalk Photoshop function
runPhotoshop("Hello", arr, 99.99, obj);
/**
* Run function in ID after BT function is completed
* @Param the string or object returned from Photoshop
* @Return void
*
*/
function runID(s){
//if the return is an array as a string use split
//alert("Running New ID Fuction—string returned from Photoshop: " + s.split(",")[1])
alert("Running New ID Fuction—string returned from Photoshop: " + s)
}
/**
* Opens Photoshop via Bridgetalk and runs psScript
* @Param the string or object sent to Photoshop
* @Return value void
*
*/
function runPhotoshop(s, a, n, o){
//open Photoshop and run psScript
var bt = new BridgeTalk();
bt.target = "photoshop";
//a string representaion of variables and the function to run.
//a string var. Note string single, double quote syntax '"+s+"'
bt.body = "var s = '"+s+"';"
//an array. Note use toSource()
bt.body += "var a = "+a.toSource()+";"
//a number
bt.body += "var n = "+n+";"
//an object. Note use toSource()
bt.body += "var o = "+o.toSource()+";"
//the function and the call
bt.body += psScript.toString() + "psScript();";
bt.onResult = function(resObj) {
runID(resObj.body)
}
bt.onError = function( inBT ) { alert(inBT.body); };
bt.send(8);
function psScript() {
//make a new string
var ns = s + " World " + a[2] + " " + n + " " + o.h;
//returns the array as a string
//return a
return ns
}
}
Copy link to clipboard
Copied
Really appreciated. Thank you!
Copy link to clipboard
Copied
Hello, guys.
I can make the bridgeTalk to deal with my folder.
But, when I use functions and save my script as jsxbin, it's stoping with an error on Mac systems. I think it's because of something Loic mentioned in another thread. Not sure.
Any idea?
Copy link to clipboard
Copied
But, when I use functions and save my script as jsxbin, it's stoping with an error on Mac
Do you mean you are calling additional Photoshop functions? Make sure any Photoshop functions are inside of the BridgeTalk body. So here the Photoshop function getName() works:
//InDesign as the script application
#target indesign
#targetengine "session"
runPhotoshop();
function runID(s){
alert("Running New ID Fuction—string returned from Photoshop: " + s)
}
function runPhotoshop(){
var bt = new BridgeTalk();
bt.target = "photoshop";
//the function and the call
bt.body += psScript.toString() + "psScript();";
bt.onResult = function(resObj) {
runID(resObj.body)
}
bt.onError = function( inBT ) { alert(inBT.body); };
bt.send(8);
function psScript() {
//a photoshop function run inside of psScript()
function getName(){
return app.activeDocument.name
}
return getName()
}
};
But if the getName() function is outside of psScript() I get an error—getName is not a function:
runPhotoshop();
function runID(s){
alert("Running New ID Fuction—string returned from Photoshop: " + s)
}
function runPhotoshop(){
var bt = new BridgeTalk();
bt.target = "photoshop";
//the function and the call
bt.body += psScript.toString() + "psScript();";
bt.onResult = function(resObj) {
runID(resObj.body)
}
bt.onError = function( inBT ) { alert(inBT.body); };
bt.send(8);
function psScript() {
//a photoshop function run inside of psScript()
return getName()
}
function getName(){
return app.activeDocument.name
}
};
Copy link to clipboard
Copied
Thanks Rob.
I have almost the same you sent.
A funcion as string and a string calling that function.
Then, within that function called in the bt.body, I have another three functions.
My client (Mac user) reported this error:
Then I sent the script as jsx and no error was shown.