(Note to the future: I report some things/make some claims about the state of the code and the pre-built binaries that are currently true, but may not be so by the time you read this.)

(Note 2: I name all my electronic devices using technical terminology of air travel or air traffic control. Airspace is my main machine)

I have set up a small application (minute-agent by Tom MacWright) on my Mac that logs the number of keystrokes on a system-wide level and records those frequencies to a comma-delimited file every 1 minute.

To be clear, the client is not recording which keys I am pressing, just how many of them I press every minute. Also, it has never tried to use the network, so even if you are paranoid about what the open-source application is recording, it’s not talking to anyone about anything.

I’ll provide a quick/simple guide to getting this set up on your machine, I’ll explain the time format the program uses, detail one modification that I made, and give a quick report on how I plot the log file with R.

Before I continue, I should link to The Personal Analytics of My Life by Stephen Wolfram, which was my first exposure to long-term collection of personal analytics, and features the largest number of mind-blowing plots I have ever seen. This man has logged every keystroke of his since 2002, and every email he’s sent or received since 1989.

Simple and fast setup

First of all, you need to be running OS X.

Second of all, I have only tested this on 10.8 (and the original author of the program tested it on 10.7), but who knows, maybe it will also work on 10.6.8.1

Setting up the agent is very simple. Go to the minute-agent GitHub site, scroll down to the README.md file and read it, then download the pre-compiled binary here.

Before you can actually run it, you need to enable access for assistive devices.

To do this, go to System Preferences -> Accessibility -> check the box titled Enable access for assistive devices.

Unzip the archive you downloaded, drag hihowareyou.app to your Applications folder, and launch it. It will pop up a message letting you know that since the program is running for the first time, it will create your log in:

~/Documents/minute/keystrokes.log

Once you click OK, you should be all set. From that point onwards, the minute-agent will appear in your menu bar (where you can click on it for easy Quitting), and will log the number of keystrokes you’ve made to the keystrokes.log file every 2 mins.

Differences between pre-built binary and source code

Right now, the binary (.app) that you download differs from the code that’s current on GitHub.

The .app saves the log to

~/Documents/minute/keystrokes.log

But if you download the code and compile from source like I did, you’ll find that it saves the log to

~/logs/keystrokes.log

Other than that, as far as I can tell, the pre-built binary and the code are the same program.

“What the hell kind of time is ‘1356730200’?”

If you’ve run the program for a little while and then looked at the log file, you may have blurted out something similar. I sympathize. I’ve been there. On the other hand, if you know what Unix time is, you rock.

I don’t want to speak much on a subject I am not an expert on. All I will do is link to Unix or POSIX time while telling you that Unix time is the number of seconds that have elapsed since 00:00 (UTC) January 1st, 1970.

I will also tell you that you can convert from UNIX time to a format that can be parsed by humans using the Terminal as follows:

$ date -r 1356730200

Which should return

Fri 28 Dec 2012 16:30:00 EST

Logging every 1 min instead of every 2 mins

Right now, the source code or binary that you download will log every 2 mins. That’s not bad. However, I wanted the higher sampling rate of 1 min, which then gives me the freedom to do with the data as I please. You can produce a per 2-min plot or representation from 1-min sampling, but not the other way around.

To do this, you need to:

  1. Download and install Xcode2
  2. Download the minute-agent source code (or fork it on GitHub or do whatever it is git wizards do)

Once you unzip the code archive, open hihowareyou.xcodeproj in Xcode. Click on/edit the HHAYController.m file.

Line 116 reads:

if (nextTick - lastTick > 60) {

Change that 60 to a 30

if (nextTick - lastTick > 30) {

And you’re done. Save, and build the application by clicking on Product menu -> Build, move the compiled hihowareyou.app to your Applications folder, and once you run it, it will log the number of keystrokes every minute to ~/logs/keystrokes.log

If you want this logging to continue on the long-term, you will need to make sure OS X runs hihowareyou.app every time it boots. You can do this by going to System Preferences -> Users & Groups, clicking on your username, and adding hihowareyou.app to your Login Items.

Plotting the log with R

As I mentioned ~/logs/keystrokes.log is a comma-delimited file. Meaning that it will look something like this:

To product a similar plot to the one you see in the image above, you can use the following R script:

Nice, yes?

  1. If you’re still running Snow Leopard, honestly, I salute you. 

  2. If there is another way of compiling an Xcode project without Xcode, I don’t know it.