Is it possible to evaluate an expression in launchd's ProgramArguments array?
Got an answer in the original Stack Overflow question, Is it possible to evaluate an expression in launchd's ProgramArguments array?

It is possible by means of this bash command:

/bin/bash -c '/bin/launchctl setenv JAVA_HOME $(/usr/libexec/java_home -v1.8)'


The plist file you want is as follows:

&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt;
&lt;plist version="1.0"&gt;
&lt;dict&gt;
    &lt;key&gt;Label&lt;/key&gt;
    &lt;string&gt;test.so&lt;/string&gt;
    &lt;key&gt;ProgramArguments&lt;/key&gt;
    &lt;array&gt;
        &lt;string&gt;/bin/bash&lt;/string&gt;
        &lt;string&gt;-c&lt;/string&gt;
        &lt;string&gt;/bin/launchctl setenv JAVA_HOME $(/usr/libexec/java_home -v1.8)&lt;/string&gt;
    &lt;/array&gt;
    &lt;key&gt;RunAtLoad&lt;/key&gt;
    &lt;true/&gt;
    &lt;key&gt;ServiceIPC&lt;/key&gt;
    &lt;false/&gt;
&lt;/dict&gt;
&lt;/plist&gt;