🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: adobe.scripting.indesign
10 messages
10 total messages Started by cinematomico Wed, 21 Jan 2009 12:40
$setenv and $getenv problem
#1879
Author: cinematomico
Date: Wed, 21 Jan 2009 12:40
14 lines
1069 bytes
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!
Re: $setenv and $getenv problem
#1889
Author: xbytor
Date: Wed, 21 Jan 2009 16:57
8 lines
990 bytes
> 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
Re: $setenv and $getenv problem
#1893
Author: cinematomico
Date: Wed, 21 Jan 2009 17:30
4 lines
736 bytes
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.
Re: $setenv and $getenv problem
#1894
Author: xbytor
Date: Wed, 21 Jan 2009 17:49
15 lines
1310 bytes
> 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
Re: $setenv and $getenv problem
#1895
Author: cinematomico
Date: Wed, 21 Jan 2009 18:14
2 lines
730 bytes
Yeah I saw something about those Windows Registry while googling but I have to develop this script for a mac based client.
Thanks again!
Re: $setenv and $getenv problem
#1954
Author: xbytor
Date: Wed, 21 Jan 2009 22:11
18 lines
1394 bytes
> 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
Re: $setenv and $getenv problem
#1953
Author: Harbs
Date: Thu, 22 Jan 2009 05:05
7 lines
840 bytes
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
Re: $setenv and $getenv problem
#1962
Author: Kasyan Servetsky
Date: Thu, 22 Jan 2009 08:18
18 lines
1077 bytes
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
Re: $setenv and $getenv problem
#1965
Author: cinematomico
Date: Thu, 22 Jan 2009 09:59
4 lines
725 bytes
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!
Re: $setenv and $getenv problem
#1966
Author: cinematomico
Date: Thu, 22 Jan 2009 10:17
10 lines
1013 bytes
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!
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads