My previous post scheduling system revolved around the Unix
at command to schedule one-off future tasks. In the most recent version of OS X (10.10.4), that atrun command is utterly broken. Running
atrm will give you:
atq: cannot regain privs: Operation not permitted
I couldn’t find any way to fix it, so I revamped the system. It now uses a lightweight launchd task that polls for dates listed in a simple text file. This is a simple solution that works well because I can easily edit the file remotely and modify it with other scripts.
The code that follows uses my notifyutil-based system to trigger the
rake generate_deploy command that builds and uploads my static blog. You can also experiment with just running that command directly from a script, but because Jekyll has specific dependencies and most people use bundler/rvm/rbenv with it, the fact that launchd doesn’t load your shell environment may be problematic. The idea remains the same, though.
First, the script that the launchd task uses to check for new date triggers. It just reads in a file called “scheduled_deploys.txt” in the root of your Jekyll directory, parses each line, and if a line contains a date that’s before the time the task runs, it deletes the line and runs the build command.
And here’s the launchd job that polls every 5 minutes. To load it, edit the script path in the file and save it to
~/Library/LaunchAgents/rb.jekyllpoller.plist (or whatever name you like), then run
sudo launchctl load ~/Library/LaunchAgents/rb.jekyllpoller.plist.