Setting up an auto-publishing workflow

A quick note on how I’m syncing Bear with this site, since I haven’t done this before.

I’m using launchd to update this site the with the most recent content from Bear every minute. Right now, there’s hardly any content here so the inefficiency of re-generating and re-deploying everything is not a problem.

The launchd bit was a bit prickly to figure out, so I figured I’d write it down here. ChatGPT helped with a lot of the basics. Here are the instructions I ended up with (just pub is a recipe that uses the excellent Just command runner):

Save this to ~/Library/LaunchAgents/is.yuri.pubcommand.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>is.yuri.pubcommand</string>

    <key>StartInterval</key>
    <integer>60</integer>

    <key>ProgramArguments</key>
    <array>
      <string>/bin/zsh</string>
      <string>-c</string>
      <string>just pub</string>
    </array>

    <key>WorkingDirectory</key>
    <string>/Users/yurivish/Dropbox/Projects/what</string>

    <key>StandardOutPath</key>
    <string>/tmp/what_yuri_is_output.log</string>

    <key>StandardErrorPath</key>
    <string>/tmp/what_yuri_is_error.log</string>

    <key>EnvironmentVariables</key>
    <dict>
      <key>PATH</key>
      <string>/Users/yurivish/.cargo/bin/:/usr/local/go/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin</string>
    </dict>

    <key>RunAtLoad</key>
    <true/>
  </dict>
</plist>

Then run:

launchctl unload ~/Library/LaunchAgents/is.yuri.pubcommand.plist
launchctl load   ~/Library/LaunchAgents/is.yuri.pubcommand.plist

This will automatically run the publication command every minute, publishing the #pub notes from Bear.

To temporarily disable the scheduled job, you can unload the plist using launchctl:

launchctl unload ~/Library/LaunchAgents/com.user.pubcommand.plist

This will stop the job from running without deleting the plist file. To re-enable it later, simply load it again:

launchctl load ~/Library/LaunchAgents/com.user.pubcommand.plist

You can see logs by tailing the paths specified in the plist file under StandardOutPath and StandardErrorPath.