Long ago, I had seen Nat
Friedman show off a small Mono app that displayed the amount of time you spent
on each application, and updated the chart in real time – so that you could
clearly make out how much time you’re spending in the browser and how much time
you’re actually spending on work.
I couldn’t locate that app, so I had been wanting to write my own version for a
long time and finally got around to doing it today.
It turned out to be easier than I thought. First, I had to figure out how to
find out what application has the current focus at any point in time, and I was
trying to see if I can do it from Python (using the Win32 extensions, and yes,
this hack is Windows-only). After a lot of searching, I finally found out that
it boils down to just one line:
win32gui.GetWindowText(win32gui.GetForegroundWindow()) and this
would fetch the title of the application that the user is using at that moment.
After this, all I had to was record the window title every 5 seconds and
increment the time spent for each window, and voila, the data is ready. I was
quite satisfied with just a command line output, but
Raghu egged me on to create a Flex chart frontend
for it as well, and when Harish joined in, the fun
really got started. The first problem was how to push the data from Python
to Flex, and we use the oldest trick in the book – write it to a file. Next,
Flex can read the same file as long as the file is in the same directory as
the SWF (i.e. the Flash file) location. Then we parse the text to get back
the original data, create a pie chart and point it to this data, and voila
we have a beautiful chart:
Now I can finally track what I actually end up doing the whole day, heh. You can
download the files if you want to use it as well:
- The Python script called “BigBrother.py”
- The MXML file called “BigBrotherGUI.mxml”
- The compiled SWF file for those who don’t
want to go through the hassle of compiling the MXML to SWF.
- Just run/open both
BigBrotherGUI.swfat the same time
and watch the statistics.
And who said meetings aren’t productive ;-)