I have created a global environment variable by adding a LaunchDaemon plist file as described in this article. I have some troubles though.
If I call:
envQTBIN is not in the list.echo $QTBINnothing is returned./bin/launchctl getenv QTBINThe path is returned.
I am using this in a Python 3 script which is used on both Windows and macOS and are therefore accessing QTBIN with the command os.getenv("QTBIN"). However, this command returns None when executed on macOS. This makes me assume it builds upon command option 1 or 2 above.
Question How can I create an environment variable that is accessible to all programs and available in Python on both Windows and macOS? If possible, I would like to avoid having os specific code in the python script. I think the preferred solution will be to have QTBIN occur in the env list.
My plist file: /Library/LaunchDaemons/setenv.QTBIN.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>setenv.QTBIN</string>
<key>ProgramArguments</key>
<array>
<string>/bin/launchctl</string>
<string>setenv</string>
<string>QTBIN</string>
<string>/usr/local/Cellar/qt/5.14.1/bin</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>ServiceIPC</key>
<false/>
</dict>
</plist>
Command to load environment variable without restarting:
launchctl load -w /Library/LaunchDaemons/setenv.QTBIN.plist.