5 Replies Latest reply on Sep 19, 2016 1:34 AM by Heimdaal

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

    Heimdaal Level 1

      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.

        • 1. Re: Trying to get path of running JSX ($.filePath not working)
          Pedro Cortez Marques Level 3

          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.

          • 2. Re: Trying to get path of running JSX ($.filePath not working)
            Heimdaal Level 1

            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);

            • 3. Re: Trying to get path of running JSX ($.filePath not working)
              Pedro Cortez Marques Level 3

              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

              • 4. Re: Trying to get path of running JSX ($.filePath not working)
                Heimdaal Level 1

                That is correct - my scripts are located in the main.jsx of my panel.
                c:\Users\martin.dahlin\AppData\Roaming\Adobe\CEP\extensions\com.myCustomPanel\jsx\main.jsx

                 

                So I guess that the $.fileName function is rather dumb and not really working with panels. If this is indeed the case then is there another way of getting the path to the panel and/or script???

                 

                Also: I tried running alert($.fileName); in jsh* and then I got the correct path to the script So it appears that you only get this weird result when executing scripts from a panel.

                 

                *(a javascript shell. Google for Photoshop xtools and you'll find it - it's super-useful!)

                • 5. Re: Trying to get path of running JSX ($.filePath not working)
                  Heimdaal Level 1

                  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