Launch Agent will not run shell script

3k views Asked by At

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

3

There are 3 answers

1
tripleee On BEST ANSWER

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

0
vadian On

You need the full path to the script. The default permissions for launch agents in the user domain are 644

Update: Using both keys KeepAlive and StartInterval is problematic. As the script is supposed to run every minute, delete the KeepAlive key and value

0
silicontrip On

I've made this work So I can only assume that your plist file has an error or option to prevent it from running. This is my plist that works.

<?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>net.silicontrip.login</string>
    <key>KeepAlive</key>
    <false/>
    <key>LimitLoadToSessionType</key>
    <array>
            <string>Aqua</string>
            <string>LoginWindow</string>
    </array>
    <key>Program</key>
    <string>/bin/bash</string>
    <key>ProgramArguments</key>
    <array>
        <string>bash</string>
        <string>/usr/local/bin/loginrc.sh</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
</dict>
</plist>

This both works immediately after a launchctl load or a login.