osx - Is it possible to evaluate an expression in launchd's ProgramArguments array? -


i have ~/library/launchagents/setenv.java_home.plist file contains /bin/launchctl call follows:

<?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.java_home</string>     <key>programarguments</key>     <array>         <string>/bin/launchctl</string>         <string>setenv</string>         <string>java_home</string>         <string>$(/usr/libexec/java_home -v1.8)</string>     </array>     <key>runatload</key>     <true/>     <key>serviceipc</key>     <false/> </dict> </plist> 

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

question is: possible compose plist file expression evaluated , not treated literal value? and, if so, how?

as you've discovered, <string> entries passed string literals, $(/usr/libexec/java_home -v1.8) bash shell expression. according the launchd.plist documentation, programarguments takes array of strings, there not appear way of marking argument expression.

however, think simple solution run /bin/bash -c argument, followed command line want execute.

<?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>test.so</string>     <key>programarguments</key>     <array>         <string>/bin/bash</string>         <string>-c</string>         <string>/bin/launchctl setenv java_home $(/usr/libexec/java_home -v1.8)</string>     </array>     <key>runatload</key>     <true/>     <key>serviceipc</key>     <false/> </dict> </plist> 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -