Skip to main content
Inspiring
August 12, 2019
Question

get extension path withing jsx file

  • August 12, 2019
  • 2 replies
  • 2160 views

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.

This topic has been closed for replies.

2 replies

Justin Taylor-Hyper Brew
Community Expert
Community Expert
August 12, 2019

$.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;

karpiyonAuthor
Inspiring
August 12, 2019

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.

Justin Taylor-Hyper Brew
Community Expert
Community Expert
August 12, 2019

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.

Trevor:
Legend
August 12, 2019

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.