Dynamically setting HOME environment variable in a launchd script? Continue from this topic, I ended up with:

&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE plist PUBLIC "-//Apple Computer//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;com.saltstack.minion&lt;/string&gt;
    &lt;key&gt;EnvironmentVariables&lt;/key&gt;
    &lt;dict&gt;
      &lt;key&gt;HOME&lt;/key&gt;
      &lt;string&gt;/Users/quanta&lt;/string&gt;
    &lt;/dict&gt;
    &lt;key&gt;ProgramArguments&lt;/key&gt;
    &lt;array&gt;
      &lt;string&gt;/usr/local/bin/salt-minion&lt;/string&gt;
    &lt;/array&gt;
    &lt;key&gt;RunAtLoad&lt;/key&gt;
    &lt;true/&gt;
  &lt;/dict&gt;
&lt;/plist&gt;


but I am wonder that: is there any way to set HOME variable dynamically? (instead of fixed code - /Users/quanta)

I have tried to add an EnableGlobbing key to the plist:

&lt;key&gt;EnableGlobbing&lt;/key&gt;
&lt;true/&gt;


then changed the value of HOME variable to the tilde:

&lt;key&gt;EnvironmentVariables&lt;/key&gt;
&lt;dict&gt;
  &lt;key&gt;HOME&lt;/key&gt;
  &lt;string&gt;~&lt;/string&gt;
&lt;/dict&gt;


and restart the salt-minion. Here is what I get:

MacBook-Pro.local:
    - /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/pathname.rb:853:in `expand_path': non-absolute home (ArgumentError)
    -   from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/pathname.rb:853:in `expand_path'
    -   from /usr/local/Library/Homebrew/global.rb:25:in `cache'
    -   from /usr/local/Library/Homebrew/global.rb:44
    -   from /usr/local/Library/brew.rb:17:in `require'
    -   from /usr/local/Library/brew.rb:17


It seems that expansion is only enabled for strings in the Program or ProgramArguments keys.
You are right: launchd performs tilde-expansion only for ProgramArguments. But you are free to let a shell do the job:

&lt;key&gt;ProgramArguments&lt;/key&gt;
&lt;array&gt;
    &lt;string&gt;/bin/sh&lt;/string&gt;
    &lt;string&gt;-c&lt;/string&gt;
    &lt;string&gt;export HOME=~; /usr/local/bin/salt-minion&lt;/string&gt;
&lt;/array&gt;


Note that the ~ in this example is not interpreted by launchd (using EnableGlobbing) but by the shell itself.