System attribute breaks unicode?

Here is a little test - save the following foo.scpt


set accountName to system attribute "FOO"

and in Terminal do this:


export FOO="Lumière"
osascript foo.scpt

And you’ll see garbled text instead of the correct “Lumière”.

Adding “as Unicode Text” to the foo.scpt doesn’t help.

I know I can do


do shell script "echo $FOO"

to get the env var - but in practice I have half dozen variables to pass around, and the script needs to be run fairly frequently - I don’t want to start 6 shell processes in the background just to get the env variables!

Any suggestion is extremely welcome!

Hi,

You could encode the string as HEX in the environment variables and then ‘run script’ it in a ‘data’ or ‘utf8’ event when you retrieve it into AS. That might be just as slow, though. You might be able to write the string out to a file (maybe after a tweak) and read it back in as Unicode text. That might be faster, but it’d be more complicated. The easiest solution would be to arrange things so you could get all of the variables at once with one shell call; I assume that’s not possible for your case?