Matthew's Weblog

Org mode clocking in the macOS menu bar

I make most of my income by developing iOS, Android and web apps for UK-based clients. I'll work with clients to specify, design, code and maintain software.

For most projects, I'll provide clients with a fixed price quote based on the agreed scope. Other work may be a fixed charge each month to provide support and maintenance, or occasionally I work on a time and materials basis. For each scenario, I need to track how much time I spend carefully. The profitability of fixed-price work depends on an accurate estimation of the time required, and exact time tracking is essential to remaining profitable. For time and materials work, I need to know how much to charge the client. Some support and maintenance agreements have limited rollover of time to the next month, so I need to know precisely how much time has been spent.

There are a plethora of paid time tracking solutions. I have no objections to paying for good software where it is of genuine benefit - after all, I pay for my mortgage, bills, food and shelter by people paying me for software I've developed! However, where possible, I want essential data, such as my time tracking records, to be in open formats, under my control and in a form I can quickly interrogate.

As an Emacs and Org mode user, I have a fantastic feature for tracking my time. Org mode clocking allows me to track time against specific headlines. As I use Org mode for planning projects, keeping notes and managing my tasks, it makes sense to keep my time tracking there.

For each project, I create a new file using Org roam. This file will contain headlines such as invoicing, tasks, notes, file links and time tracking. When I spend time on that project, I 'clock in' to the time tracking headline in that file.

Whenever I'm working on mobile apps, I'm likely spending lots of time in Xcode or Android Studio. To make my current Org mode clock glanceable, I've used the app xbar to add my timer to the macOS menu bar. It is super simple to write your scripts for xbar, and it took only a few minutes to write one to ask Org mode for the required information.

#!/usr/bin/env zsh

# <xbar.title>Show current Org mode clocked-in entry</xbar.title>
# <xbar.version>v1.0</xbar.version>
# <xbar.author>Matthew Kennard</xbar.author>
# <xbar.author.github>appsonthemove</xbar.author.github>
# <xbar.desc>If you use Org mode clocking to track time against tasks, this plugin will show you the current clocked-in task and the elapsed time</xbar.desc>

function client {
    /usr/local/bin/emacsclient --eval "$1"
}

if  `client "(org-clock-is-active)"` == "nil"  ; then
    echo "No Task"
else
    echo -n '⏱'
    client "(org-clock-get-clock-string)" | head -n 1 | cut -d'"' -f2
    echo '---'
    echo 'Clock out | shell=/usr/local/bin/emacsclient | param1=--eval | param2="(org-clock-out)" | refresh=true'
fi

I've been using this now for over a year. I'm hoping at some point to add the following to this system:

If I ever get around to either of those I'll let you know!


Recent posts