MacOS – Configure launchd

launchdmacos

I have a launchd plist in ~/Library/LaunchAgents designed to run a script located at ~/writout.sh every day at 10:30AM:

<?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>local.jackson.testwrite.plist</string>
    <key>Program</key>
    <string>/Users/jacksonkearl/writeout.sh</string>
    <key>StartCalendarInterval</key>
    <dict>
        <key>Hour</key>
        <integer>10</integer>
        <key>Minute</key>
        <integer>30</integer>
    </dict>
</dict>
</plist>

The script is:

#!/bin/bash
echo "it works" >> log.txt

However, nothing gets written at the desired time.

Are there steps I must take to alert launchd to the new agent? Or how else do i make the process start?

Best Answer

You need to load the launch agent into launchd.

  1. Open Terminal
  2. Type cd ~/Library/LaunchAgents
  3. Type launchctl load -w local.jackson.testwrite.plist (assuming that is the name of your plist file)

This will load and persistently enable your plist. You can check if it is loaded with launchctl list