Skip to main content
nimazz
Participant
June 29, 2011
Answered

How to get the windows username in jsx

  • June 29, 2011
  • 2 replies
  • 3169 views

Hello,

I have a JSX script in "My Documents\Adobe Scripts" to make it trusted script. I have another text file I need to read from JSX. Since the location depends on logged in user, I need to find the windows username. If anyone know how to get the windows username from jsx please reply.

Thank you very much.

Regards

Nima.

This topic has been closed for replies.
Correct answer tomaxxi

Hey,

You can get username like this:

var myUsername = $.getenv('username');

You could also get My Documents folder like this:

var myDocFolder = Folder.myDocuments;

Hope that helps.

--

Marijan (tomaxxi)

http://tomaxxi.com/

2 replies

tomaxxi
tomaxxiCorrect answer
Inspiring
June 29, 2011

Hey,

You can get username like this:

var myUsername = $.getenv('username');

You could also get My Documents folder like this:

var myDocFolder = Folder.myDocuments;

Hope that helps.

--

Marijan (tomaxxi)

http://tomaxxi.com/

Inspiring
July 13, 2011

How about the username on a Mac?

கற_பன___Imagine_
Inspiring
November 11, 2011

Well, which system name? There are a few different ones. I'd use

app.doScript('do shell script "hostname"', ScriptLanguage.APPLESCRIPT_LANGUAGE);

But you can also do tricks in the filesystem with resolving : paths...


Thank you so much,

I've used the file system tricks for getting the exact results.

if (File.fs == "Windows" ) {

    var myUserName  = $.getenv('username');

    var mySysName  = $.getenv('computername');

    }

else if (File.fs == "Macintosh") {

           var myUserName  = $.getenv('USER');

           var mySysName  = app.doScript('do shell script "hostname"', ScriptLanguage.APPLESCRIPT_LANGUAGE);

    }

Thanks once again........

nimazz
nimazzAuthor
Participant
June 29, 2011

Hello,

I found the answer .

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

this works fine.

Regards