Big Brother

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:

big brother gui example

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:

And who said meetings aren’t productive ;-)


  1. Chris J Andrews made a JavaScript GUI

  2. Theyagarajan modified the Python script to make it work on

27 thoughts on “Big Brother

  1. you could clearly make out how much time you’re spending in the browser and how much time you’re actually spending on work.

    Man! do u still believe that you can do all your work without actually using a browser. Definitely not a case with me :-P

  2. Hola Bro… so you finally made the app production material. I’m proud of you :) And you should be too… Your first (predominantly MXML) Flex App ;)

    Seriously… Really cool app maga. A Flexible Python is a deadly animal :)

  3. I wanted such an app too and I had downloaded few freeware/shareware…one of them put the data into excel and also it had start clock -stop-clock stuff. Only thing was, it was not possible to increase the time interval (I wanted more than 5 sec)!

  4. Wouldn’t it easier to update flex front over XML/Binary Socket?

    Python app can run in background listening over some socket. Flex app connects on that socket and updates in real-time..


  5. Next, detect the current tab in firefox so that you can track whether your browser is on a work-related page or not ;)

  6. How do I compile the mxml file? I’ve never used flex before. I tried compiling this with the free flex2 cmdline compiler, but got errors related to PieChart. What do I need to do to configure the mxmlc compiler environment?

  7. there is a bug! both at home and office, I only see orange color(firefox) in the whole graph ;) :D

    seriously speaking,
    cool app! why not make it a google desktop widget?

  8. To paint a clearer picture, you’d have to say what was active in the browser at each point of time. If bugzilla was open, which bug. If a monitoring app was open, which product, etc.

  9. I’m pretty sure spo0nman is out there kicking himself …

    He’s got a half-finished application which does something identical in X11 land (called ‘centuple’), with xprop.

    The thing it had extra is that it has a config file which lets you tag based on regexes. That should be powerful enough to do what bluesmoon suggested – i.e /Bug #/ tagged as bugzilla for instance.

  10. Shame it does not work on Mac OS X because of the win32gui import in the Python script. There may be a way to call the x86 gui to do the same thing. I’ll try it later …

  11. @Azmi: Well, yes.

    @Raghu: It was fun!

    @RK: You can tweak the Python script as you wish.

    @Abdul: How would it be “easier”? :) Would it be better? Yes.

    @Taj, Philip, t3rmin4t0r: Yeah, I’ve sort of done it for myself but removed out those parts when posting on the blog since it is too specific for me. You can tweak the title_to_application function to do whatever you want.

    @Prasun: Sorry about that. As Pradeep already mentioned, it’s not part of the standard SDK. I just realized it’s the same reason why I had never used it until now :)

    @Cedric: Let me know if you can get it working on Mac.

  12. is there a similar functionality in pygtk ?
    i would love to do a similar app for for my ubuntu box :)

  13. Do you know the api to do the same thing for Linux(Ubuntu).. After reading this article, Just wanted to try on Linux as well.

    thank you

  14. @Taggy: Thanks for the heads-up, I’ve fixed the permissions.

    @Ranganath: Please see the link to Theyagarajan’s in the update to the post.

    @Calvin: It splits the text of the title window by the dash, so title like ‘Swaroop C H, The Dreamer – Mozilla Firefox’ gets converted to just ‘Mozilla Firefox’.

  15. I cannot see the Pie Chart in Firefox. Both the swf
    and the code are in same directory and I double-clicked
    the swf to open it in Firefox. The ‘BigBrotherSays’ file
    has data ‘Mozilla Firefox=40,Windows Task Manager=25,
    python,C:=5,Program Manager=5’

    Windows XP SP2. Firefox

  16. @Toji: Have you tried running the python script and check if it updates the data file? And then try running the swf… I guess you’ll have to debug whether the flex app is actually able to find and read the file or not.

  17. Thanks for suggestions, Swaroop.

    You: “Have you tried running the python script and check if it updates the data file?”

    Me: Yes. That’s why we’ve data in the file; right?

    You: “I guess you’ll have to debug whether the flex app is actually able to find and read the file or not”

    Me: Yes. I went through the mxml and guess that url=”BigBrotherSays.txt” may not be accurate (particularly when I run the swf inside a browser). The correct way to get the file name may be to use the ‘url’ property of ‘Application’ class. See and

    Disclaimer: This is the first time in my life that I look into an mxml file!

Comments are closed.