Setting GUI Visible Environment Variables with OS Catalina I need to set a number of Environment variables that can be seen by GUI apps (i.e. Xcode). When running from a terminal this is trivial and is simply a case of adding a. number of export commands to my .bash_profile e.g.

export BOOST_INCLUDE=~/boost/boost-XXXX/boost


Unfortunately GUI apps do not see values set in .bash_profile. I am using Catalina and it appears that Apple modifies the mechanism every time MacOs is updated. Many online guides are out of date....

This article: http://www.dowdandassociates.com/blog/content/howto-set-an-environment-variable-in-mac-os-x-launchd-plist/ suggests that launchctl should do what I need but even the following simple example does not work:

In a terminal:

/bin/launchctl setenv FOO BAR


Then close the terminal and open a new one

Check the value:

echo $FOO


The output should be 

BAR


But it is unset. Note it is also unset in the original terminal so I am not convinced that the command /bin/launchctl setenv FOO BAR is doing anything.

Note: This is about setting the environment variable for GUI apps NOT just for the terminal.
Run launchctl setenv FOO BAR in Terminal.app, then quit (Cmd-Q) and restart Terminal.