$.getenv('Path')

LEGEND ,
Dec 05, 2017 Dec 05, 2017

Copy link to clipboard

Copied

$.getenv('Path')

- when you launch Photoshop and and run a script with above code or target Photoshop from Extendscript the first path from all displayed will be to Photoshop

- when you launch Bridge and and run a script with above code or target Bridge from Extendscript the first path from all displayed will be to Bridge

but:

- when you launch Photoshop and then run Bridge from Photoshop manually (File / Browse in Bridge...) or by script were is command to launch Bridge

and you use $.getenv('Path') whatever from Extendscript with targeted Bridge or from the script the first path there will be displayed won't be to Bridge but Photoshop!

- when you launch Bridge and then run Photoshop from Bridge manually (File / Open with Photoshop) or by script were is command to launch Photoshop

and you use $.getenv('Path') whatever from Extendscript with targeted Photoshop or from the script the first path there will be displayed won't be to Photoshop but Bridge!

Well it makes problem! Because no matter you run Photoshop and Bridge or Bridge and Photoshop,

where the second program is ran from your system or from first program it always should gives path of the program you target or run script from.

Scenario:

Some script works in Photoshop/Bridge but then needs information from Bridge/Photoshop.

a) If both programs were launched separately from system (Windows / OS), and then $.getenv('Path') is used all is okey.

b) If only one program was launched from system and second from that program which was lunched first or from the script targeted one program but then calling another $.getenv('Path') end is completely useless!

Is it bug or some specific behaviour? Well some users can open second program from that first or a script will do it. How then chance behaviour of that second program. I mean ho to make it could use $.getenv('Path') like it was launched from system?

For now it seems like first program is kind of parent of that second, like system for programs ran in. I can close by script that second program and use File(<path>).execute() of course to open that second program. Then it will be opened by system.

But it is not a way. If I did that then I had to use a path, which I don't know, so I want to get by $.getenv('Path') which has to tell me path to application I want to open (no matter there is also app.path). It's about finding solution for the problem I'm describing.

So command line and Autohotkey is no an option too, as in their cases I also has to put the path, which I can't know when I don't know were exacactly and what program is installed by someone who uses my script with $.getenv('Path')

Any ideas what can be done in this situation? If there is not then some workaround? and like I asked before is it bug or specific behaviour?

TOPICS
Actions and scripting

Views

2.5K

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guide , Dec 06, 2017 Dec 06, 2017
Why not use :-alert(decodeURI(Folder.startup));Bridge does not give anything for app.path;

Likes

Translate

Translate
Adobe Community Professional ,
Dec 06, 2017 Dec 06, 2017

Copy link to clipboard

Copied

It is usually difficult for me to understand all the nuances of the problems described in English.

Could you give a maximally simplified example of the scrip (s) where the problem can arise because of the first value change in Path.

I do not have and I do not use Bridge, so I can not check anything. I can only suggest in theory.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 06, 2017 Dec 06, 2017

Copy link to clipboard

Copied

I wrote my 'question' in notapad then pasted during creating new topic with intention to edit it in some parts as it copied some unexpected spaces between next paragraphs and generally was too long. Unfortunately I found out I can't edit (even unanswered) new topics created myself like that's possible with answers to someone topic/post. I can't understand what is this limitation for? Anyway if I couldn't edit it then I wanted to completely remove my new topic to create it again with corrected content. Well there's no option also for that! So I left ugly looking original topic! It seems only I can do is to create another theard with the same corrected content. So there would be 2 similar topics. What if I find another thing to correct before someone answer? I have to create another topic? It's stupid, but I guess moderators delete those older versions, however that isn't fun, so better if not let users for editing their new created topics then at least give chance to remove them. Is there such option to enable by administrator/moderator in Jive forums or we have to live with this nonsene?

--------------------------------------------------------------------------------------------------------------------------------------------

r-bin you don't need to have bridge. It's sufficient you have Photoshop and ExtendScript toolkit. Just do the following:

1) Open Photoshop from system, then ESTK from system too (or in other order).

2) try this code in ESTK:

$.getenv('Path')

First path will be: C:\ProgramData\Oracle\Java\javapath

3) now thry this code:

#target photoshop

$.getenv('Path')

It's again correct, so first path will be: C:\Program Files\Adobe\Adobe Photoshop CS6 (64 Bit)\

you can save code from item 3 as script and run from photoshop, it'll give expected result (photoshop path)

4) to display correct path of ESTK calling it from Photoshop it's not so obvious. You can't just use following code ran in Photoshop:

#target estoolkit

alert($.getenv('Path'))

as it displays you Photoshop path in Photoshop (for some reason it doesn't take you to ESTK, and also doesn't open it when it's not launched)

You have to use this code:

BT = '(function BT(v1, v2) {bt = new BridgeTalk(), bt.target = v1, \

bt.body = v2, bt.onResult = function(v) {return res = v.body} bt.send(2)})'

function ge() {alert($.getenv('Path'))}

eval(BT + "('estoolkit', '(' + " + ge.toString() + " + ')()')")

so Bridge Talk, which let you for communication between Adobe applications

(still you don't have to have Bridge to use it as 'BridgeTalk' isn't the same what 'Bridge')

Anyway, when you save above code as script and run from photoshop it show you that 'specific' ESKT path in this case

--------------------------------------------------------------------------------------------------------------------------------------------

Now do it the way one application launches second:

1) Open Photoshop from system and run a script with code you used last time (from Photoshop as well), so:

BT = '(function BT(v1, v2) {bt = new BridgeTalk(), bt.target = v1, \

bt.body = v2, bt.onResult = function(v) {return res = v.body} bt.send(2)})'

function ge() {alert($.getenv('Path'))}

eval(BT + "('estoolkit', '(' + " + ge.toString() + " + ')()')")

it won't display C:\ProgramData\Oracle\Java\javapath in first line of array-like message, but Photoshop path

2) Now close both programs and try it that you open first ESTK and then following code you run as script from system or paste to ESTK editor and play:

#target photoshop

BT = '(function BT(v1, v2) {bt = new BridgeTalk(), bt.target = v1, \

bt.body = v2, bt.onResult = function(v) {return res = v.body} bt.send(2)})'

function ge() {alert($.getenv('Path'))}

eval(BT + "('photoshop', '(' + " + ge.toString() + " + ')()')")

(#target photoshop in first line is needed only when you execute script from system)

however in this case you could use (alerted if ran from system or with/out when from ESTK) simple:

#target photoshop

alert($.getenv('Path'))

it won't display Photoshop path in first line of array-like message, but C:\ProgramData\Oracle\Java\javapath

--------------------------------------------------------------------------------------------------------------------------------------------

well I hope now you understand and give me solution for this problem

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Dec 06, 2017 Dec 06, 2017

Copy link to clipboard

Copied

How many letters ).
But as far as I understand you did not describe the problem more serious

than the "wrong" output of the function alert($.getenv('Path')).

More serious problems can be? Why do you need to see the path to the application in the first line of the "Path", especially It is not in the system variable "Path"?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 06, 2017 Dec 06, 2017

Copy link to clipboard

Copied

In Bridge you have File / Open or just Ctrl+O to open files in default or Adobe program you opened Bridge from. It works the same way as you right clicked on some selected image(s) in Bridge and choose Open or just double right clicked on selected object(s). If you open Bridge from other program like Photoshop then there is no problem opening such selected image by Bridge (script). It'll be opened immediately in Photohop.

If you open Bridge (when Photoshop isn't opened yet) and use Bridge (script) to open an image in Photoshop when you doing by sole Bridge normaly it open images in Photoshop, though sometimes during first 10 seconds after launching Bridge it doesn't see Photoshop as default program and then open images in Windows image browser or if that is not set then ask what program with you'd like to open an image.

Like I say it happens only sometimes during first 10 seconds when you do it by Bridge, but unfortunatelly always when you open image during first 10 seconds by Bridge script. You could say that's only 10 seconds and to avoid it people can open Photoshop in first instance and then Bridge from it. Well I meet many situations that it's not so easy people acted one way due to instructions, and there are different situations sometimes you simply can't avoid it happened like you want.

Well I found solution for this problem. There is also File / Open With command in Bridge you can choose also by right clicking an selected image(s). When you do it right after opening Bridge there is never problem even when Photoshop is not opened yet, but when you do it by Bridge script there must specified path you put inside of script command openWith brackets.

So what is problem? I can't use one path for all Photoshops, as people use different versions of them on OS or Windows. Solution is simple, Bridge can ask Photoshop of its path To do it you need BridgeTalk message with getenv('Path'). If Photoshop was launched before Bridge then Bridge as an answer get Photoshop path and can open selected images in Photoshop. But when Photoshop isn't launched yet, then Bridge to get information from Photoshop (about its path for example) it has to lanuch Photoshop. If it happens then Photoshop is kinda process not of a system (however it is) but of Bridge. At least Bridge sees it in this one case like it's children.

Well, the back message from Photoshop about its path is Bridge path! And because images can't be opened in Bridge because they alrady are a script gives error as it 'belives' the path it recieved is correct. As far as Photoshop was launched by Bridge any next time you try to open an image nothing happens, beside script continues execution (or there was some code to stop it).

To test it (when Photoshop isn't launched) there can be used following code from ExtendScript ToolKit:

#target bridge

BT = '(function BT(v1, v2) {bt = new BridgeTalk(), bt.target = v1, \

bt.body = v2, bt.onResult = function(v) {return res = v.body} bt.send(2)})'

function ge() {alert($.getenv('Path'))}

eval(BT + "('photoshop', '(' + " + ge.toString() + " + ')()')")

If Bridge is already launched you'll see Bridge path will be alerted as first.

When both Photoshop and Bridge aren't running then you get the path specific for ESTK in Photoshop alert.

Well, either I leave in a script File / Open command and enforce Bridge to freeze for time there left to full 10 seconds after running a script from Bridge, or I use File / Open with command in a script and there will be situations that someone who doesn't have idea of scripting can't get what happens. Such person close Bridge then open again to run script. What will happen? Nothing, as still Photoshop will be a process of closed Bridge, though new session was started So someone close Photoshop, but then run script from already launched Bridge, and all happen again, until that person realize to open Photoshop separately. Of course even this won't give expected result. Why? Because to run a script from Bridge you have to bind it to some Bridge menu. If you do it then information of Photoshop path is set to variable, later any time you run script it reffers to. So opening new session of Photoshop won't help because path stored in variable keeps information of first Photoshop session, however it's still Bridge path for reasons I described above. Someone simply will think he did everything what there can be done and perhaps won't open Photoshop and then Bridge to check can it help as an user will give up

It's why I wanted solution or workaround for getenv('Path') when second application was ran by first, so not seen by it like opened directly from system.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Dec 06, 2017 Dec 06, 2017

Copy link to clipboard

Copied

/*

You are not accessing the system environment variable "Path"

You are accessing a local variable called "Path" in Photoshop

Example:

*/

#target photoshop;

$.setenv("Path" ,"");

alert($.getenv("Path"));

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 06, 2017 Dec 06, 2017

Copy link to clipboard

Copied

Well, I know you can set your environment variables. But $.getenv("Path") is already set, or is set at the moment you want to get it (if of course like you show someone before didn't change it to its own value). That I'm saying is when one program launches second one then path you check for that second program is incorrect, as it is stuck to path of first program. The only option I see is to launch all programs separately before beeing in one of them you want to browse images in second.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Dec 06, 2017 Dec 06, 2017

Copy link to clipboard

Copied

OK. I read for a long time, I tried to understand. As I understand you need to know the path of the photoshop installed in the system. If so then your method of using the first value in Path does not work at least on my home computer.

The simplest script

alert(app.path.fsName + "\n\n\n" + $.getenv("path"))

Gives the result.

Untitled-1.png

Not at all what you want )).

For you, I can offer two methods so far. One is to set the independent constant variable PhotoshopPath and read its value.

You can install it manually or use a script (on windows)

function set_photoshop_path()

    {

    try

        {

        var cmd = "var WshShell=WScript.CreateObject(\"WScript.Shell\");" + "\r\n" +

                  "var s = String(WshShell.RegRead(\"HKLM\\\\SOFTWARE\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\App Paths\\\\Photoshop.exe\\\\Path\"));" + "\r\n" +

                  "if (s.charAt(s.length-1) == \"\\\\\") s = s.substr(0, s.length-1);" + "\r\n" +

                  "WshShell.Run(\"setx PhotoshopPath \"+\"\\\"\"+s+\"\\\"\", 0);"+ "\r\n" +

                  "var fso=new ActiveXObject(\"Scripting.FileSystemObject\");\r\nfso.GetFile(fso.GetSpecialFolder(2).Path+\"\\\\tmp.js\").Delete();";

        var file = new File(Folder.temp.fsName + "\\" + "tmp.js");

        file.encoding = "BINARY";

        file.open("w");  if (file.error) { alert(file.error); return false; }

        file.write(cmd); if (file.error) { alert(file.error); return false; }

        file.close();

        file.execute();

        return true;

        }

    catch (e) { alert(e); return false; }

    }

It can be called each time as needed, although it is enough once.

The only downside is that after its very first call, the application must be restarted otherwise getenv ("PhotoshopPath") sees nothing.

The second script reads from the registry exactly the path of the photoshop and it's the one that is substituted into the Path variable when you start the photoshop.

function get_photoshop_path()

    {

    try

        {

        var ret = null;

        var cmd = "var ws=WScript.CreateObject(\"WScript.Shell\");" + "\r\n" +

                  "var fso=new ActiveXObject(\"Scripting.FileSystemObject\");" + "\r\n" +

                  "var f=fso.GetSpecialFolder(2).CreateTextFile(\"photoshoppath\",true,true);" + "\r\n" +

                  "f.WriteLine(ws.RegRead(\"HKLM\\\\SOFTWARE\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\App Paths\\\\Photoshop.exe\\\\Path\"));" + "\r\n" +

                  "f.Close();" + "\r\n" +

                  "fso.GetFile(fso.GetSpecialFolder(2).Path+\"\\\\tmp.js\").Delete();";

        var file = new File(Folder.temp.fsName + "\\" + "tmp.js");

        file.encoding = "BINARY";

        file.open("w");  if (file.error) { alert(file.error); return null; }

        file.write(cmd); if (file.error) { alert(file.error); return null; }

        file.close();

        file.execute();

        while(file.exists) $.sleep(10);

        var file = new File(Folder.temp.fsName + "\\photoshoppath");

        file.open("r");      if (file.error) { alert(file.error); return null; }

        ret = file.readln(); if (file.error) { alert(file.error); return null; }

        file.remove();

        return ret;

        }

    catch (e) { alert(e); return null; }

    }

Both scripts use the start of an external script through the wscript. There may be problems with anti-virus programs blocking execution.

While such a decision if it's on the topic at all

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 06, 2017 Dec 06, 2017

Copy link to clipboard

Copied

If I understood well from alert you pasted to the post, you launched Photoshop CS6 and it showed correct CS6 path however $.getenv('Path') ran from the same version of Photoshop gave unexpected result. It showed path to latest Photoshop CC 2018 version on your computer? Well, if so then using $.getenv('Path') is pointless when there are more than one version of Photoshop on the computer as it may not refer to the version of Photoshopp you run script from. That's bad if that alert was created like it. But maybe I'm wrong?

Both scripts worked. At first glance they were complex for me, but generally understable. I didn't think of going beyond photoshop scripting, but I like this way of approching to problem. (Btw at first time of running them Dreamweaver was launched I had to find tmp.js you created by script to see that DW for some reason was set to execute .js files. I deleted it from registry like DW icon of JSfiles as well.) But isn't it making next problem. I use one Photoshop on the computer so this solution fits me temporarily but what if there are more Photoshops in one system? Which of version's paths will be pointed?

I was in registry to see how it looks like. In my case there was only one photoshop.exe ran for CS6 but if I had other version which would be choosen? (default, last open?) and if so, if I opened other version of Bridge with intention to use it with its version of Photoshop I understand that I couldn't do it, as 'PhotoshopPath' would take me to other version of Photoshop than that related to Bridge I opened, isn't it so?

Still great THX for your work. I learnt something new to me. You showed your mastered skills and probably can find solution for more problems I perhaps come to this forums with. Even if my doubts come true I can think of using these scripts for my other needs, like using in some future to reach registry information what I never did so far. Anyway if not SuperMerlin Folder.startup method I certainly used yours, more complex but working. The only question is won't be there problem on someone's computer with more Photoshop's installed (while all are being used).

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Dec 07, 2017 Dec 07, 2017

Copy link to clipboard

Copied

I probably will not be able to help you here.

I do not have the opportunity and interest to solve the problems of Bridge and its scripts.

I think that Bridge does not matter which version of Photoshop to run.

In the registry there is recorded the path to the most recently installed or updated Photoshop.

Therefore it is correct to run this version.

How it's easier to read from the registry by useing script, I have not invented yet.

)

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 08, 2017 Dec 08, 2017

Copy link to clipboard

Copied

LATEST

There you find path to script I made using your code for my needs: Proof Colors script!

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Dec 06, 2017 Dec 06, 2017

Copy link to clipboard

Copied

Why not use :-

alert(decodeURI(Folder.startup));

Bridge does not give anything for app.path;

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 06, 2017 Dec 06, 2017

Copy link to clipboard

Copied

@SuperMerlin I didn't read all documention so I didn't know this method. It works well. I can use it instead of getenv('Path'), however I still hope someone find some workaround for the problem I met. Yes app.path does nothing in Bridge (I don't know what happened meantime I thought it doesn't, so if not method you prosopsed I really had problem with some of my scripts other users in my work use...

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines