Note: This site is currently "Under construction". I'm migrating to a new version of my site building software. Lots of things are in a state of disrepair as a result (for example, footnote links aren't working). It's all part of the process of building in public. Most things should still be readable though.

Automatically Restart launchd Scripts On Change

This is the launchd script I use to restart launchd scripts when I'm working on them.

Code

~/Library/LaunchAgents/com.theidofalan.restart_launchd_scripts.plist
<?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>com.theidofalan.restart_launchd_scripts</string>
    <key>ProgramArguments</key>
    <array>
        <string>/bin/bash</string>
        <string>-c</string> 
        <string>
touch /tmp/launchd_ping_a.txt
launchctl unload ~/Library/LaunchAgents/com.alanwsmith.* || true
launchctl load ~/Library/LaunchAgents/com.alanwsmith.* 
touch /tmp/launchd_ping_b.txt
        </string> 
    </array>
	  <key>WatchPaths</key>
    <array>
        <string>/Users/alan/Library/LaunchAgents</string>
    </array>
    <key>StandardErrorPath</key>
    <string>/tmp/launchd_auto_restart.log</string>
    <key>StandardOutPath</key>
    <string>/tmp/launchd_auto_restart.log</string>
</dict>
</plist>