Watch a folder to update website

Purpose

As soon as a file get added or modified from my local website folder, it automatically gets updated on the server too.

Make the plist file

We create the following file:

~/Library/LaunchAgents/com.yoricm.watchwebsite.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.yoricm.watchwebsite.plist</string>
    <key>StandardErrorPath</key>
  <string>/Users/ym/Documents/__Boulot/__yoricm/__dl/watch_website/err.log</string>
    <key>StandardOutPath</key>
  <string>/Users/ym/Documents/__Boulot/__yoricm/__dl/watch_website/out.log</string>
    <key>EnvironmentVariables</key>
    <dict>
        <key>PATH</key>
        <string>/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin</string>
    </dict>
    <key>WorkingDirectory</key>
    <string>/Users/ym/Documents/__Boulot/__yoricm/__dl/watch_website</string>
    <key>ProgramArguments</key>
    <array>
        <string>/bin/bash</string>
        <string>watch_website.sh</string>
    </array>
    <key>WatchPaths</key>
    <array>
        <string>/Users/ym/Documents/__Boulot/__yoricm/__dl/site</string>
    </array>
    <key>KeepAlive</key>
    <false/>
</dict>
</plist>

Make the bash script

We create the following file:

/Users/ym/Documents/__Boulot/__yoricm/__dl/watch/watch_website.sh:

#!/bin/bash

rsync -avh -e "ssh -p 9804" ../site/* yoricman@yoric-mangeart.net:/home/yoricman/yoricm-com/dl/

Load the plist file

We run the following command in the terminal:

launchctl load ~/Library/LaunchAgents/com.yoricm.watchwebsite.plist