Slock: the occasional clock

If I were smart, I would have kept track of the article that sparked this. But I’m not, so you’ll have to take my word for it. Some time ago I read an article in which the author suggested that one of the nastier little context-switching sources in your everyday life is checking the time. Lots of the things we do our work on have clocks, many of which are omnipresent. It’s very easy to flick your eyes up to the clock, check the time, then go back to work - and if that loses you productivity as you “switch out” of the task you’re doing, process the time, then “switch in” back to what you were working on, it could be a nasty drag on your time.

It’s easy enough to disable the clock in OS X. The problem is that this means I never know what the time is1. A few days without a clock at all lead me to the realisation that I don’t actually want to know the time all the time - I just want to know when I hit a particular time.

The solution is to have a daemon process that displays notifications at given times, but otherwise stays out of the way. The daemon with this job is slock.rb.

slock consists of two main sections:

  1. A daemon that runs every minute, checking the time against a database of times. If there is a notification that nees to be shown, it’ll show (via growl) on the desktop.
  2. A database of times to notify me on.

I’m using jcache to store all my data, since this is what I’m using for my stuff these days, but it’d be easy to swap this out for a yaml or json file somewhere else on your computer. The database is simply a yaml file with a series of times, and a “last accessed” time, which effectively tells slock whether to run notifications or not (it’ll only run notifications which occur between last_accessed and now).

The time database can be configured per day as well. I have mine set up for weekdays and weekends:

> cache slock
Contents of cache slock:
        '08:45': You should think about starting work soon...
        '09:00': It's about time to start work now.
        '13:00': Back to work.
        '15:00': Have a break! Afternoon tea time
        '17:00': End of the work day.
        '10:30': Have a break! Morning tea time.
        '12:00': Have a break! Lunch time.
        '21:00': Do you need to do anything before you go to bed?
        '22:00': Bed time.
    :last_accessed: 2013-03-17 20:02:11.259586000 +13:00

You could also add entries for particular days (keyed :monday, :tuesday, etc.) if you have particular events occuring on specific days.


Available on github.

  1. Yes, I know. There’s plenty of other ways to check the time. This is assuming that you don’t check a watch or other time-telling device.