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

[Q] Using $.getenv

Explorer ,
Dec 24, 2023 Dec 24, 2023

Copy link to clipboard

Copied

I was trying to use $.getenv on MacOS but it returns 'undefined'. Am I misunderstanding how to use it?

var envname;

$.getenv(envname);
$.writeln(envname);

 

TOPICS
Scripting

Views

186

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

Community Expert , Dec 24, 2023 Dec 24, 2023

Hi @tomd75724979, I've never actually used it, but I had a quick look and here's what I noticed:

 

First, see this note in the docs specifically for MacOS:

Screenshot 2023-12-25 at 06.41.42.png

So it claims to use launchctl setenv. So you can do this:

 

1. In a terminal session, type this:

 

launchctl setenv "foo" "bar"

 

2. launch Illustrator (the var won't be available to Illustrator unless it launches after step 1).

3. run this ExtendScript

 

// read "foo" key, alerts "bar"
alert($.getenv('foo');

 

Note: these vars are not persi

...

Votes

Translate

Translate
Adobe
Community Expert ,
Dec 24, 2023 Dec 24, 2023

Copy link to clipboard

Copied

Hi @tomd75724979, I've never actually used it, but I had a quick look and here's what I noticed:

 

First, see this note in the docs specifically for MacOS:

Screenshot 2023-12-25 at 06.41.42.png

So it claims to use launchctl setenv. So you can do this:

 

1. In a terminal session, type this:

 

launchctl setenv "foo" "bar"

 

2. launch Illustrator (the var won't be available to Illustrator unless it launches after step 1).

3. run this ExtendScript

 

// read "foo" key, alerts "bar"
alert($.getenv('foo');

 

Note: these vars are not persisent across system restarts.

 

Also note that you can do it all from in ExtendScript itself:

// write
$.setenv('foo','baz');

// read
$.writeln($.getenv('foo'));

and this var will persist as long as Illustrator is open. However, I don't think you will be able to read a var set in ExtendScript from outside, eg. by launchctl getenv "foo" because environment vars set this way seem to be passed from parent process to child, so don't go back up and to another process, eg. a terminal.

 

That's all I could tell at a quick look. Hopefully there are some experts on here that may shed more light.

- Mark

Votes

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
Explorer ,
Dec 24, 2023 Dec 24, 2023

Copy link to clipboard

Copied

Hi Mark,

 

Many thanks for your response. I now realise I completely misunderstood this. I thought this would return the machine environment, something like {Apple Macintosh, 14.0} or {Microsoft Windows, 10.x}. But I now understand that it is some overarching variable that can be accessed from multiple scripts.

Votes

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
Community Expert ,
Dec 24, 2023 Dec 24, 2023

Copy link to clipboard

Copied

for the os you can use the following. But I'm on Windows 11, so I'm not sure what the 10.0 is

$.os
// Result: Windows/64 10.0 

 

Votes

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
Explorer ,
Dec 25, 2023 Dec 25, 2023

Copy link to clipboard

Copied

LATEST

Many thanks, Carlos!

 

For me it returns:

Macintosh OS 14.0.0/64

 

Which sounds spot on.

Votes

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