Getting the path of the current script

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

Asterokid

Getting the path of the current script

Post by Asterokid »

Hello Everybody,

I am desperately trying to get the path of the script inside the script itself.
The best solution I could find for now is to get the application path with app.path and add the extra string "/Presets/Scripts" manually. Nevertheless, this means I now have to detect which OS I am running the script from in order to add the right piece of string. This seems far from ideal. If anybody wants to understand why I need that, it is because I am writing an ini file in the same place as the script to store the latest settings.

Thanks you for reading.

Professional AI Audio Generation within Adobe Premiere Pro - Download Free Plugin here

larsen67

Getting the path of the current script

Post by larsen67 »

Does… '$.fileName' not work for this? I can't check as I think the property came about in CS3…
Asterokid

Getting the path of the current script

Post by Asterokid »

Thanks, works perfectly.
Asterokid

Getting the path of the current script

Post by Asterokid »

A new silly question. Is there some kind of environment variable which returns your scripts folder path.
For example on a Mac it would be something like "/Applications/Photoshop/Presets/Scripts".

Thanks.
larsen67

Getting the path of the current script

Post by larsen67 »

If you get yourself the Javascript Tools Guides you will find under the 'folder' object of 'file system access' there are several properties that are folder shortcuts listed as this is for all apps of the suite and both OS's there is NO one hit answer for each app's scripting folder but you could possibly use these to make a shorter more flexible path…
Asterokid

Getting the path of the current script

Post by Asterokid »

Yes, none seems to hit the script folder directly, nevertheless this folder object is good to know. I will probably have to add the missing bit after detecting which OS I am running under.

Thanks.
Mike Hale

Getting the path of the current script

Post by Mike Hale »

Asterokid wrote:Is there some kind of environment variable which returns your scripts folder path.

Adobe has a z-string for that...

Code: Select all

var scriptsPath = app.path + "/" + localize("$$$/ScriptingSupport/InstalledScripts=Presets/Scripts");[code]

That should point to the scripts folder on any OS and any language version. Although it's not clear if Presets/Scripts is localized.
Asterokid

Getting the path of the current script

Post by Asterokid »

It works on Mac but I am not convince it's going to work on Windows because of these "/" we are adding to the string.
I'll try when I get home.

Thanks.
Mike Hale

Getting the path of the current script

Post by Mike Hale »

It works with Windows.

In extendscript there are two ways to build a path string for Windows. One way is to use backward slashes 'c:\\testFolder'. Note that the backward slash needs to be escaped with another back slash. You can also use '/c/testFolder'. Both string create a path to the same folder. Most of us seem to use the later method. For example '~/desktop' works on both Mac and Windows so there is no need to create two strings one for each OS.
Asterokid

Getting the path of the current script

Post by Asterokid »

Indeed it works with Windows. That's great. Thanks a lot for your advices.