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

$setenv and $getenv problem

Explorer ,
Jan 21, 2009 Jan 21, 2009
Hi, I'm tryin to set and get an environment var in InDesign CS3 (mac) using javascript.

I made a script (to InDesign) to set a var:
$.setenv("myVar", "my value");

And another one (also to InDesign) to get the var:
alert($.getenv("myVar"));

While both are running I get the var value in the alert, but when I restart InDesign and launch the second script it doesn't works.
What's the problem with this?
I thought environment vars were supposed to live even if I close the application.
Am I wrong?

Thanks anticipately guys!
TOPICS
Scripting
2.3K
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 ,
Jan 21, 2009 Jan 21, 2009
> I thought environment vars were supposed to live even if I close the application.

When you use setenv, it is modifying environment variables for that process and
any subprocesses (shells, for instance) that may be launched by that process.
When the app finishes, those settings disappear.

-X
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 ,
Jan 21, 2009 Jan 21, 2009
Thanks for this tip xbytor.
So, is there a way (apart from saving it in a file) to let a var live despite of its app closure?

Thanks 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
Explorer ,
Jan 21, 2009 Jan 21, 2009
> So, is there a way (apart from saving it in a file) to let a var live despite of its app closure?
>

There may be some weird Windows Registry stunt you could pull on XP to do this.
If it exists, it would modify the user's env vars in a persistent fashion; it
would survive a reboot, for instance.

On OS X, there may be a similar hook somewhere, but I doubt it. This kind of
thing just doesn't fit the traditional Unix model of how env vars are handled,
so it would likely require adding a setting to a plist file somewhere.

Saving it to a file is probably your best/safest bet.

-X
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 ,
Jan 21, 2009 Jan 21, 2009
Yeah I saw something about those Windows Registry while googling but I have to develop this script for a mac based client.
Thanks 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 ,
Jan 21, 2009 Jan 21, 2009
Since I've never used $.setenv or $.getenv and I might be missing
something simple... What's the advantage over just using simple global
variables?

--
Harbs
http://www.in-tools.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
Explorer ,
Jan 21, 2009 Jan 21, 2009
> What's the advantage over just using simple global
> variables?

I would only consider them useful for setting up env vars for other applications
that you maybe invoking from ID/JS.

Beyond that, $.getenv is useful for things like $HOME, etc...

$.setenv wouldn't really serve any other purpose except when:
a) you have some code that already looks to $.getenv for info.
and
b) that info isn't in your env vars (for some reason) so $.setenv can insert
some defaults

That's kind of convoluted and not what I would consider good practice when
scripting Adobe apps.

-X
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
Valorous Hero ,
Jan 22, 2009 Jan 22, 2009
Hi cinematomico,

I use application’s insertLabel and extractLabel methods to store variables between ID sessions.
For example:
// store variable

var myVariable = "my value";
app.insertLabel("myVar", myVariable);

// restore variable
if (app.extractLabel("myVar") != ""){//if myVar has been set some value
var myVariable = app.extractLabel("myVar");
}
else {//if not set some default value
var myVariable = "some default value";
}

Kasyan
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 ,
Jan 22, 2009 Jan 22, 2009
Hi Kasyan,
I didn't know the insertLabel and extractLabel instance...
I'm going to test this solution very soon.
Once again, thanks for the tip!
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 ,
Jan 22, 2009 Jan 22, 2009
LATEST
Thanks a lot guys, from a first test I have to say this solution works really well.
Just a few other questions...

Do you know where this data is stored (I mean, I think ID write it in a plist file...)?

If so, when I delete ID preferences (you know, it happens sometimes...) do I also delete these vars?

Is there any limit about var size (sometimes I have to store XML preferences data which are just enormous...)?

Cheers!
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