MacOS – Setting .plist path to user Library

daemonslaunchdmacosplist

I have created a OS X launch agent that is installed per user. It is listening socket and automatically launched when socket connection arrives. On my .plist I have

    <key>ProgramArguments</key>
    <array>
<string>~/Library/Containers/com.mycompany.myproduct/myproduct.app/Contents/MacOS/myproduct</string>
    </array> 

When connecting to my launch agent socket I get a message in console saying my launch agent is not found. When changing .plist ProgramArguments to

<string>/Users/myusername/Library/Containers/com.mycompany.myproduct/myproduct.app/Contents/MacOS/myproduct</string>

Launch agent is loaded correctly. So it looks like I need to modify .plist for each user during launch agent installation. How can I do this automatically or easily? Is there a standard way for this? Or should I do something totally differently here to achieve what I want?

Best Answer

Use EnableGlobbing:

<key>EnableGlobbing</key>
<true/>
<key>ProgramArguments</key>
<array>
    <string>~/Library/Containers/com.mycompany.myproduct/myproduct.app/Contents/MacOS/myproduct</string>
</array> 

It works with ProgramArguments but not with Program.