30 * * * * /Users/user/dev/swaptracker

Did that make sense to you? Well, me neither, but since I looked it up and wrote it, I can tell you what it does. It executes the script found at that location every hour on the half hour. Obviously, this is wrong and will result in me having a new instance of swaptracker running every hour until my system crashes because it's run out of pids or something, but the script up there prevents that. Here's what it looks like:

if ! (ps aux | rg swaptracker | rg -v rg) > /dev/null {
    swaptracker '/Users/user/Documents/swap.csv'

Here's the breakdown:

  • I tested the script with zsh, so that's what I hashbanged it with. Sorry. Sue me.
  • The script includes a path variable because cron jobs apparently do not execute with your path.
  • The only way I can find out whether or not an instance of swaptracker is running is to examine the output of ps. I then have to filter out the instance of rg swaptracker that will be running in order to avoid a false positive.
  • PowerShell is so much nicer than this...

Anyway, in theory, this script will prevent the process from being started if it is already running. It seemed to work in testing. I'll know whether it works for the real thing or not in about thirty more minutes. Now that we know what we're doing, let's discuss why.

Computers are good at doing crap automatically

...The hell they are.


My first throught was to check to see if there was a cron time thing like @logon. Short answer: no the hell there isn't. Windows offers something like that with no muss and no fuss in Task Scheduler, but, hey, maybe this is more a root kind of thing? I found that @reboot is available and gave that a try, but could not get any kind of consistent results and got tired of rebooting my machine after the first attempt.

...As an aside, Windows allows you to trigger scheduled tasks by hand...

You can hypothetically trigger a cron task by restarting some service on Sub-Basement Level 03 of macOS, but I thought that was a bit much. Time to move on. I knew the macOS guys had to ahve something else to do their dirty work, so I figured I'd just take a look at that. I ignored Automator and AppleScript and instead went straight to launchd, because I'm not paid to play with duplo blocks and eat paint.


I made it halfway through the first tutorial I found.

You know how to make an advancement in computing? Take some function a computer is already able to perform and make it more complicated, less reliable, and less efficient. Instead of a one line reference to a time and a script, let's make a task into this massive XML document instead. Of all the times for Apple to start emulating Big Mike...

Fuck launchd and the horse it XMLed in on.

Plan B

Plan B is always to hack some shit together. That's what makes the world go round, isn't it? So that's what I've done.

So far, I've had issues making the task launch, issues with it running multiple instances of itself, and issues with my issues. Luckily, the nature of the data is such that having too much of it is not a problem. Multiple instances of the process equates to greater resolution, at least provided that the processes don't deadlock. Anyway, I'll be back in a half hour to let you know how this is going.

Update 1: Had a duplicate. Modified my script. Apparently I removed a bang somewhere by mistake? Back in an hour.

Update 2: Adding back my missing bang fixed it. Check back in a week for when I write the program that processes this stupid CSV file. >.<

Sample output:

2018-02-26 22:25:10.015324 UTC,16777216,54976,2205896,0,0,0,0
2018-02-26 22:26:10.136964 UTC,16777216,97460,2161952,0,0,0,0
2018-02-26 22:27:10.283446 UTC,16777216,102712,2381348,0,0,0,0
2018-02-26 22:28:10.284128 UTC,16777216,120520,2110600,0,0,0,0
2018-02-26 22:29:10.343616 UTC,16777216,50992,2182188,0,0,0,0
2018-02-26 22:30:10.425190 UTC,16777216,51468,2170264,0,0,0,0
2018-02-26 22:31:10.496104 UTC,16777216,36580,2282744,0,0,0,0
2018-02-26 22:32:10.568506 UTC,16777216,760608,1766668,0,0,0,0
2018-02-26 22:33:10.636131 UTC,16777216,672984,1887428,0,0,0,0
2018-02-26 22:34:10.708265 UTC,16777216,126456,1987816,0,0,0,0