Slock: the occasional clock

Published
2013-03-17
Tagged

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:

1
> cache slock
2
Contents of cache slock:
3
4
5
---
6
:times:
7
      :weekdays:
8
        '08:45': You should think about starting work soon...
9
        '09:00': It's about time to start work now.
10
        '13:00': Back to work.
11
        '15:00': Have a break! Afternoon tea time
12
        '17:00': End of the work day.
13
      :always:
14
        '10:30': Have a break! Morning tea time.
15
        '12:00': Have a break! Lunch time.
16
        '21:00': Do you need to do anything before you go to bed?
17
        '22:00': Bed time.
18
    :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.

Source

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.