MacOS – Need assistance troubleshooting / learning launchctl and plist

launchdmacosplist

I've always been a crontab guy. Recently I have decided to make the switch to Apple's launchd processes, and I am unable to get my first plist to run.

  1. The plutil -lint command tells me the plist is formatted correctly. Actually, it outputs "OK".

  2. I have run the bash script manually and confirmed that it properly operates when manually initiated.

  3. I have loaded the file using launchctl load and received the response "already loaded" on repeated attempts to do the same.

The problem must be in my PLIST definition. Please help me spot the error.

I expect this to run with the following conditions:

  • Only while the user jaredclemence is using the system
  • Once immediately on login
  • Every 15 minutes thereafter
  • Change Directory to /Library/WebServer/Documents/medface/ before running the script.

The plist file is as follows:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>Label</key>
        <string>org.pediatricheartcenter.medface.crons</string>
        <key>User</key>
        <string>jaredclemence</string>
        <key>ProgramArguments</key>
        <array>
                <string>/User/jaredclemence/runMedfaceSchedTasks.batch</string>
        </array>
        <key>WorkingDirectory</key>
        <string>/Library/WebServer/Documents/medface</string>
        <key>StartInterval</key>
        <integer>900</integer>
        <key>RunAtLoad</key>
        <true/>
</dict>
</plist>

Notes:

  • I have stored the file in ~/Library/LaunchAgents/org.pediatricheartcenter.medface.crons.plist
  • A previous version of the file used Program instead of ProgramArguments with a <string> value instead of an array.

Best Answer

Launchd writes errors to system.log. Using Console, I viewed the log. There, launchd told me that it did not like my User key value. I removed the User - jaredclemence key-value pair, and loaded the plist again. It then told me the batch program did not exist and I then noticed the error in the file path. /User should be /Users

By removing the User setting and correcting the file path, I was able to fix the problem. Now, running ps -ef | grep 'runMed', I am able to see that the batch file is currently executing.

SUCCESS!