I'm trying to source
a file from a launch agent
, but it's unclear how to accomplish that (or if it's even possible). I know it's easy to setenv
for single variables, but I need to bring in a bunch of them, so source
is what I need.
<?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>my.sourcerer</string>
<key>ProgramArguments</key>
<array>
<string>source</string>
<string>my_file.sh</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>WorkingDirectory</key>
<string>/path/to/source</string>
</dict>
</plist>
This loads and starts without any issue it seems:
$ launchctl load ~/Library/LaunchAgents/my.sourcerer.plist
$ launchctl start ~/Library/LaunchAgents/my.sourcerer.plist
But when I printenv
none of my sourced environment variables show up. If manually I do:
$ source /path/to/source/my_file.sh
$ printenv
Then all of the variables show up. Why doesn't the launchctl
agent seem to load the variables into my environment?