Is it possible to evaluate an expression in launchd's ProgramArguments array? Is it possible to compose my launchd.plist file so that an embedded expression is evaluated and not treated as a literal value? And, if so, how?

I have a ~/Library/LaunchAgents/setenv.JAVA_HOME.plist file which contains a /bin/launchctl call 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;setenv.JAVA_HOME&lt;/string&gt;
    &lt;key&gt;ProgramArguments&lt;/key&gt;
    &lt;array&gt;
        &lt;string&gt;/bin/launchctl&lt;/string&gt;
        &lt;string&gt;setenv&lt;/string&gt;
        &lt;string&gt;JAVA_HOME&lt;/string&gt;
        &lt;string&gt;$(/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;


Problem is, the $(/usr/libexec/java_home -v1.8) expression is not evaluated and instead the JAVA_HOME environment variable is assigned the literal value $(/usr/libexec/java_home -v1.8).

I asked this question in Stack Overflow last week but have had so few views I'm guessing that that's not the place for it.
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;