Highlighted

Passing a $.filename path variable via bridgetalk

New Here ,
Aug 06, 2020

Copy link to clipboard

Copied

Hello there! I'm pretty new to this whole coding/scripting thing, so forgive me...

 

I'm trying to pass a variable to get the relative path to a .jsx file via bridgetalk (From Illustrator to Photoshop if that is of any matter!)

 

Here's my code:

var scriptPath = (new File($.fileName)).path 

//Bridgetalk stuff
var scriptToLoad = new File (scriptPath + "/psScript.jsx"// laddar den rätta skriptfilen
try {
    if (!scriptToLoad.exists) { throw new Error("script not found!"); }
    scriptToLoad.open ("r"); // read only
    var message = scriptToLoad.read();
    scriptToLoad.close()
catch (error) {
    alert("Error parsing the file: " + error.description);
}
#target photoshop-13
var bt = new BridgeTalk();
bt.target = "photoshop";
bt.body = message + scriptPath.toSource();
bt.send();
 
And on the other end in psScript.jsx I'm just trying to get it to alert me the path in a dialog box:
alert('Script path is: ' + scriptPath);
 
 
Adobe Community Professional
Correct answer by CarlosCanto | Adobe Community Professional

one way of doing what you need with minimal changes to your code is by

 

- wrapping your psScript in a function

- adding the function call to your bt.body. In other words, right now message refers to the psScript (which is just the function now), so we need to add the function call including the path parameter.

 

function main() {
    var scriptPath = (new File($.fileName)).path 

    //Bridgetalk stuff
    var scriptToLoad = new File (scriptPath + "/psScript.jsx") // laddar den rätta skriptfilen
    try {
        if (!scriptToLoad.exists) { throw new Error("script not found!"); }
        scriptToLoad.open ("r"); // read only
        var message = scriptToLoad.read();
        scriptToLoad.close()
    } catch (error) {
        alert("Error parsing the file: " + error.description);
    }
    //#target photoshop-13
    var bt = new BridgeTalk();
    bt.target = "photoshop";
    bt.body = message + "\nreadPath('" + scriptPath + "')";
    bt.send();
     
    //And on the other end in psScript.jsx I'm just trying to get it to alert me the path in a dialog box:
    //function readPath(scriptPath) {
    //    alert('Script path is: ' + scriptPath);
    //}
}

main();
TOPICS
Scripting

Views

58

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Passing a $.filename path variable via bridgetalk

New Here ,
Aug 06, 2020

Copy link to clipboard

Copied

Hello there! I'm pretty new to this whole coding/scripting thing, so forgive me...

 

I'm trying to pass a variable to get the relative path to a .jsx file via bridgetalk (From Illustrator to Photoshop if that is of any matter!)

 

Here's my code:

var scriptPath = (new File($.fileName)).path 

//Bridgetalk stuff
var scriptToLoad = new File (scriptPath + "/psScript.jsx"// laddar den rätta skriptfilen
try {
    if (!scriptToLoad.exists) { throw new Error("script not found!"); }
    scriptToLoad.open ("r"); // read only
    var message = scriptToLoad.read();
    scriptToLoad.close()
catch (error) {
    alert("Error parsing the file: " + error.description);
}
#target photoshop-13
var bt = new BridgeTalk();
bt.target = "photoshop";
bt.body = message + scriptPath.toSource();
bt.send();
 
And on the other end in psScript.jsx I'm just trying to get it to alert me the path in a dialog box:
alert('Script path is: ' + scriptPath);
 
 
Adobe Community Professional
Correct answer by CarlosCanto | Adobe Community Professional

one way of doing what you need with minimal changes to your code is by

 

- wrapping your psScript in a function

- adding the function call to your bt.body. In other words, right now message refers to the psScript (which is just the function now), so we need to add the function call including the path parameter.

 

function main() {
    var scriptPath = (new File($.fileName)).path 

    //Bridgetalk stuff
    var scriptToLoad = new File (scriptPath + "/psScript.jsx") // laddar den rätta skriptfilen
    try {
        if (!scriptToLoad.exists) { throw new Error("script not found!"); }
        scriptToLoad.open ("r"); // read only
        var message = scriptToLoad.read();
        scriptToLoad.close()
    } catch (error) {
        alert("Error parsing the file: " + error.description);
    }
    //#target photoshop-13
    var bt = new BridgeTalk();
    bt.target = "photoshop";
    bt.body = message + "\nreadPath('" + scriptPath + "')";
    bt.send();
     
    //And on the other end in psScript.jsx I'm just trying to get it to alert me the path in a dialog box:
    //function readPath(scriptPath) {
    //    alert('Script path is: ' + scriptPath);
    //}
}

main();
TOPICS
Scripting

Views

59

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Aug 06, 2020 0
Adobe Community Professional ,
Aug 06, 2020

Copy link to clipboard

Copied

one way of doing what you need with minimal changes to your code is by

 

- wrapping your psScript in a function

- adding the function call to your bt.body. In other words, right now message refers to the psScript (which is just the function now), so we need to add the function call including the path parameter.

 

function main() {
    var scriptPath = (new File($.fileName)).path 

    //Bridgetalk stuff
    var scriptToLoad = new File (scriptPath + "/psScript.jsx") // laddar den rätta skriptfilen
    try {
        if (!scriptToLoad.exists) { throw new Error("script not found!"); }
        scriptToLoad.open ("r"); // read only
        var message = scriptToLoad.read();
        scriptToLoad.close()
    } catch (error) {
        alert("Error parsing the file: " + error.description);
    }
    //#target photoshop-13
    var bt = new BridgeTalk();
    bt.target = "photoshop";
    bt.body = message + "\nreadPath('" + scriptPath + "')";
    bt.send();
     
    //And on the other end in psScript.jsx I'm just trying to get it to alert me the path in a dialog box:
    //function readPath(scriptPath) {
    //    alert('Script path is: ' + scriptPath);
    //}
}

main();

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 06, 2020 2
Styr0xx LATEST
New Here ,
Aug 06, 2020

Copy link to clipboard

Copied

A thousand thanks mate, this helped! 🙂

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 06, 2020 0
Resources