Extendscript current script path
Asked Answered
L

5

21

I want to get the absolute folder path of current running Extendscript.

i.e __DIR__ in php (or) __dirname in nodejs. Equivalent in Extendscript.

Ludewig answered 16/5, 2012 at 21:20 Comment(0)
L
44

Found it myself, it is $.fileName

For the folder name, it is (new File($.fileName)).parent

Ludewig answered 16/5, 2012 at 22:30 Comment(5)
FYI (if anybody is following), the folder path is returned without any trailing backslach, and it is already in extendscript format, for example: /c/some%20folde%20with%spaces/some/folder -but the script likes this.Torquemada
Might I clarify: $.fileName returns the absolute path to the current executing script, not the opened file (e.g. the .ai file you're editing in Illustrator).Darrow
At least in Illustrator, this only works when you open the script in ExtendScript, and execute it. It doesn't work when you open it directly.Gifted
Mind you, while $.fileName works fine in the context of "pure" scripting execution, it may return garbage (like a random integer) if you evaluate in the context of an HTML Panel in some Adobe applications such as Photoshop. In that case, if you need to get the absolute path of a JSX, you may want to use CSInterface.prototype.getSystemPath()Doty
var scriptFolder = (new File($.fileName)).parent.fsName;Selfdetermination
P
5

I wrote an article about this you may find helpful, :)

essentially:

var myPath = (app.activeDocument.fullName.parent.fsName).toString().replace(/\\/g, '/');
var myScriptPath = (File(app.activeScript.fullName).parent.fsName).toString().replace(/\\/g, '/');

alert('Document path is: ' + myPath + ' , and script path is: ' + myScriptPath);

mim,

Possess answered 13/2, 2015 at 23:3 Comment(0)
C
3
File($.fileName).path;

Seems to do the job nowadays

Closeknit answered 29/7, 2020 at 19:13 Comment(0)
P
1

If you need to reference files relative to the active document you can use app.activeDocument.filePath.

Pipit answered 7/5, 2013 at 12:34 Comment(2)
Note this is specific to Photoshop. $.filename works across all apps.Covered
app.activeDocumentapp.activeScriptRensselaerite
R
-1

app.activeScript.parent should do the trick - note that if you use a windows file link, you get the actual script location, not the one of the .lnk-file.

Rensselaerite answered 4/7, 2016 at 10:2 Comment(2)
FYI this is invalid for extendscript in After Effects.Stedmann
Same for PhotoshopWille

© 2022 - 2024 — McMap. All rights reserved.