Binary Lion Studios

I code for fun and for food.

Console alarm clock

Wake up with a warm cup of Coffeescript. I am constantly amazed at how simple it is to write one-off scripts and small utilities with node.js & coffeescript.

I wanted an easy way to set reminders for myself throughout the day. For example, if I put the kettle on the stove, come back to my office and crank Gungor, I’m not going to hear the kettle whistling when the water is boiled. Instead, when I get back to my office I want to open a new tab in Terminal and type:

1
$ remindme +5min "Check the kettle."

Ideally, this will show me a Growl notification and play a sound to remind me to go check on the kettle.

Using node-growl, datejs and play.js the final script is as simple as this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env coffee

nm = "#{__dirname}/node_modules"

require "#{nm}/datejs"

growl = require "#{nm}/growl"
play = require "#{nm}/play"

usage = ->
  console.log '''
    usage: remindme time msg

      time - the time to show the reminder
      msg  - the message to show when the reminder goes off
    '''

main = ->
  [time, msg] = process.argv[2..3]
  if not time? or not msg?
    usage()
    process.exit 1
  showReminder = ->
    play.sound "#{__dirname}/audio/alarm.wav"
    growl msg,
      title: 'Reminder'
      sticky: true
  remindAt = Date.parse(time)
  delta = remindAt - Date.now()
  console.log "reminding you at #{remindAt.toString()}."
  console.log "that is in #{delta}ms, if you were wondering."
  setTimeout showReminder, delta

main()

Now I can leverage the power of datejs on the console, which gives me a lot of flexibility when setting alarms. Again, I’m impressed at the number of quality libs available for node.js and the speed of which an idea can go from concept to working script.

I plan to package this script up as an npm module and make the source available on Github soon.