Search code examples
macosbashshellplistlaunchd

Launch Agent will not run shell script


Below is my plist:

<plist version="1.0">
    <dict>
<key>EnableGlobbing</key>
<true/>
    <key>Label</key>
        <string>com.system.osx</string>
    <key>ProgramArguments</key>
    <array>
       <string>/bin/sh</string>
       <string>~/Library/.system/connect.sh</string>
    </array>
<key>KeepAlive</key>
<true/>
<key>ResetAtClose</key>
<true/>
    <key>RunAtLoad</key>
        <true/>
    <key>StartInterval</key>
        <integer>60</integer>
    <key>AbandonProcessGroup</key>
        <true/>
    </dict>
</plist>

Before I run load the plist I always:

A. chmod 777 ~/Library/.system/connect.sh

B. chmod 777 ~/Library/LaunchAgents/com.system.osx.plist

C. check to make sure my script works by doing sh ~/Library/.system/connect.sh and it always does.

D. launchctl load ~/Library/LaunchAgents/com.system.osx.plist

and after loading the plist, the shell script does not run, and as you see in the plist I have made sure it runs /bin/sh first.

Any help is greatly appreciated, recently my questions have just been ignored on here.

UPDATE

I have changed ~/Library/.system/connect.sh to /Users/MyUser/Library/.system/connect.sh` and it is still not running the shell script


Solution

  • If you are on OSX Yosemite (10.10) or newer, you can no longer refer to your home directory with ~/ even if you have EnableGlobbing set to <true/>. Ref: https://apple.stackexchange.com/a/153149/15940