• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

get extension path withing jsx file

Engaged ,
Aug 12, 2019 Aug 12, 2019

Copy link to clipboard

Copied

Hi,

Within .js file i can fine the extension root using:

var csInterface = new CSInterface();

var extensionRoot = csInterface.getSystemPath(SystemPath.EXTENSION)

how do i get the extension path from within .jsx file?

I want to use:

    var scriptDir =<path to extensionRoot>/host/libs

    var scriptFile = "/myScript.jsx";

    var runScript = File(scriptDir + scriptFile);

    $.evalFile (runScript);

my jsx file is under extentionRoot/host

myScript is under extentionRoot/host/libs

Until recently my scriptDir was external but i want to move everything under the extension folder.

Views

1.9K

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
community guidelines
Guru ,
Aug 12, 2019 Aug 12, 2019

Copy link to clipboard

Copied

Did you look at my JSX.js A Game Changer in Adobe HTML Extensions Development? – Creative-Scripts.com  ?

If you use that you can just use $.__dirname

You can look at the source code there of how that is done.

Votes

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
community guidelines
Community Expert ,
Aug 12, 2019 Aug 12, 2019

Copy link to clipboard

Copied

$.fileName gives you the path to the current JSX file, from there you can find the directory:

var filePath = $.fileName;

var fileDir = (new File(filePath)).path;

fileDir;

Votes

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
community guidelines
Engaged ,
Aug 12, 2019 Aug 12, 2019

Copy link to clipboard

Copied

This is the 1st thing i tried but this yields the path to Photoshop installation, not the the extension root.

i need this definition which is in the js file

var extensionRoot = csInterface.getSystemPath(SystemPath.EXTENSION)

but in my jsx file.

Votes

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
community guidelines
Community Expert ,
Aug 12, 2019 Aug 12, 2019

Copy link to clipboard

Copied

Just tested and

var filePath = $.fileName; 

var fileDir = (new File(filePath)).path; 

fileDir; 

alert(fileDir)

Works for me in Photoshop 20.0.5, although it has to be run from a saved JSX file or from a function in a saved file, it won't work if you run it straight from csInterface.evalScript() without calling a function within a JSX file, cause otherwise it's an anonymous function and $.fileName make no sense in that case.

Votes

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
community guidelines
Engaged ,
Aug 12, 2019 Aug 12, 2019

Copy link to clipboard

Copied

i placed, as you suggested, this in my main.jsx:

function getExtRoot(){

    var filePath = $.fileName;

    var fileDir = (new File(filePath)).path;

    alert(fileDir);

    return fileDir;

}

At the bottom i have my actual function whic should run my final script.

When set scriptDir to the full puth it is working, when i use it like this it returns the path to Photoshop installation

function createSplitWrapper(panelData) {

    var scriptDir = getExtRoot();

    var scriptFile = "/createSplitLayout.jsx";

    var runScript = File(scriptDir + scriptFile);

    alert("scriptDir:" + scriptDir + "\nrunScript" + runScript);

    $.evalFile (runScript);

}

Votes

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
community guidelines
Engaged ,
Aug 12, 2019 Aug 12, 2019

Copy link to clipboard

Copied

I gave up...

I simple passed the path as a variable from the js to the jsx.

Votes

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
community guidelines
Community Expert ,
Aug 12, 2019 Aug 12, 2019

Copy link to clipboard

Copied

LATEST

Your example works fine on my machine. Maybe you have another panel or section of code modifying the $ object somewhere.

Also, there's nothing wrong with the js to jsx approach, that's how it's done in the sample.

Votes

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
community guidelines