Skip to main content
Inspiring
September 14, 2016
Answered

Trying to get path of running JSX ($.filePath not working)

  • September 14, 2016
  • 2 replies
  • 6780 views

I'm trying to get the location of the directory of the current script (main.jsx of my panel).
I've tried using $.filePath without success...

alert($.filePath);
Returns undefined or an int

var thisFile = new File($.fileName);
alert(thisFile);

Returns /c/Program%20Files/Adobe/Adobe%20Photoshop%20CC%202015

var thisFile  = new File($.fileName).parent;

alert(thisFile .fsName);

Returns C:\Program Files\Adobe\Adobe Photoshop CC 2015

What am I doing wrong?
I need to get the path of the running script file so I can do .parent to get it's folder name, and from there get a sibling folder name where I have some stuff to retrieve. I'm running this in my main.jsx -file.

This topic has been closed for replies.
Correct answer Heimdaal

Found the solution!

By running this code in the javascript file of your extension you will get the path:

var csInterface = new CSInterface();

var extensionRoot = csInterface.getSystemPath(SystemPath.EXTENSION) + "/jsx/";

alert(extensionRoot);

Credits goes to Davide Barranca

2 replies

HeimdaalAuthorCorrect answer
Inspiring
September 19, 2016

Found the solution!

By running this code in the javascript file of your extension you will get the path:

var csInterface = new CSInterface();

var extensionRoot = csInterface.getSystemPath(SystemPath.EXTENSION) + "/jsx/";

alert(extensionRoot);

Credits goes to Davide Barranca

Pedro Cortez Marques
Legend
September 14, 2016

Hi

Using this

File($.fileName).fsName

you'll get  C:\Program Files\Adobe\Adobe Photoshop CC 2015\[scriptName.jsx]

Using this

decodeURI(File($.fileName))

you'll get  /c/Program Files/Adobe/Adobe Photoshop CC 2015/[scriptName.jsx]

Or, to get the folder:

Using this

File($.fileName).parent.fsName

you'll get  C:\Program Files\Adobe\Adobe Photoshop CC 2015

Using this

decodeURI(File($.fileName).parent)

you'll get  /c/Program Files/Adobe/Adobe Photoshop CC 2015

You only need to use decodeURI() if not getting fsName, because fsName result is always decoded.

HeimdaalAuthor
Inspiring
September 14, 2016

It's not working.
Using your first example, I get:

C:\Program Files\Adobe\Adobe Photoshop CC 2015\526

then the second time I use it I get

C:\Program Files\Adobe\Adobe Photoshop CC 2015\527

The number increments for each time I run the function where I have alert(File($.fileName).fsName);

Pedro Cortez Marques
Legend
September 14, 2016

Hi

Oh I have noticed just now that you are not putting your scripts in the scripts folder.

They should be here:

C:\Program Files\Adobe\Adobe Photoshop CC 2015\Presets\Scripts\

I have put a script jsx file in the photoshop scripts folder containing this:

alert(File($.fileName).fsName);

and the alert came up with this:

C:\Program Files\Adobe\Adobe Photoshop CC 2015\Presets\Scripts\myScriptFile.jsx