Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to get the windows username in jsx

New Here ,
Jun 29, 2011 Jun 29, 2011

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.

TOPICS
Scripting
3.1K
Translate
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

Advisor , Jun 29, 2011 Jun 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/

Translate
New Here ,
Jun 29, 2011 Jun 29, 2011

Hello,

I found the answer .

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

this works fine.

Regards

Translate
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
Advisor ,
Jun 29, 2011 Jun 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/

Translate
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
New Here ,
Jun 29, 2011 Jun 29, 2011

Hi Marijan,

That's was helpful. thanks for the quick response.

Regards

Nima

Translate
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
Explorer ,
Jul 13, 2011 Jul 13, 2011

How about the username on a Mac?

Translate
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 ,
Jul 13, 2011 Jul 13, 2011

You can use $.getenv('USER'); I can't help feeling there should be a platform-independent solution though...

Translate
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
Explorer ,
Jul 13, 2011 Jul 13, 2011

Thanks!

I was pretty surprised myself that it wasn't.

Translate
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
Engaged ,
Nov 10, 2011 Nov 10, 2011

Hi,

How to get the system name on mac?

Translate
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 ,
Nov 10, 2011 Nov 10, 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...

Translate
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
Engaged ,
Nov 11, 2011 Nov 11, 2011

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........

Translate
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 ,
Nov 11, 2011 Nov 11, 2011
LATEST
Thank you so much,

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

Not quite what I meant. Try this:

(new File("/..").displayName)

Translate
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