Friday, June 29, 2012: pmd: A Command-Line Pomodoro Timer for Mac
Today, I started applying The Pomodoro Technique, so I made for myself a simple countdown timer.
This blog post also covers how to make a NSStatusItem that lives at the far right of the items.
As I usually work with the Terminal, this app must be easily usable from the Terminal. But I also want to always see the time remaining.
The result is pmd. It is invoked from the command-line, and displays the remaining time at the status bar, finally, it sends a Growl notification.
The command is written in Shell Script, with the countdown timer written in MacRuby.
To use, just invoke from the terminal:
Then the countdown will show.
Making a Status Bar Item Go Far Right
Originally, I wrote the countdown in Objective-C and working with it feels like an overkill.
There is an Xcode project file, a
main.m, the app delegate stuff (
and finally an .app file.
So I rewrote it in 42 lines of MacRuby.
The code shown here will be from the Objective-C version though.
Usually, when running a status bar application, the new status bar item gets added to the left of the status bar.
To make it go to far right, we must use Cocoa’s private API.
statusItem = [[NSStatusBar systemStatusBar] _statusItemWithLength:0.0 withPriority:INT_MAX];
But the length parameter is not used when doing it this way, so after creating the item, we need to set its length.