I have wasted most of the day trying to get some simple environment variables set that will be visible to GUI apps along with shell variables. I have tried virtually everything I've found on the web, but I can get a variable set with launchctl to visible in bash. I have a script that runs as a login item that does a simple launchctl setenv FOO BAR
. When I type launchctl getenv FOO
it returns BAR
. If I type echo $FOO
I get an empty string. I can't believe apple would something this simple so hard. I must be missing something. Am I?
When you type launchctl setenv FOO BAR
in a Terminal you are setting the variable in launchd
environment. You will have to restart the Terminal (and all its processes) to see the change. The command launchd
will pass your new variable while starting the Terminal and it will be visible in its new instance, by running echo $FOO
. The same applies to all other such applications.