Big Brother

7 minute read

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 frontend.

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


Swaroop says:

@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'.

Azmi says:

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

Abdul Qabiz says:

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..


A Flexible Python is a deadly animal « FLEXing My Muscle says:

[...] Flexible Python is a deadly animal Check out this really cool app by my dear friend and colleague Swaroop. He’s combined the power of Flex and [...]

taj says:

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

Prasun says:

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?

Anush says:

Sexy :)

Srikanth Thunga says:

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?

Philip says:

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.

t3rmin4t0r says:

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.

Cédric Rabasse says:

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 ...

Pradeep says:

you need the chart library too. Trials version of which can be downloaded from the Flex site.

Swaroop says:

@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.

Domingo Aguilera says:

Nice work.

It would be great if flash stuff would be generated by OpenLaszlo.


Its My Life …… » Big Brother -2 says:

[...] script for windows can be found at Swaroop`s blogTechnorati Tags: python, hack, [...]

taggy says:

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

Allagappan says:

Hey, taggy did a Big Brother in ubunut(though it uses ltfx)

taggy says:

the java GUI is not accessible . says Permission Denied

Ranganath.S says:

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

Ranganath.S says:

cool one! Its great!

Raghu says:

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 :)

Rk says:

I wanted such an app too and I had downloaded few freeware/ 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)!

Swaroop says:

@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.

Calvin Spealman says:

How does this work with apps that constantly change their titles, such as editors, winamp, firefox, etc.?

Toji Leon says:

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!

Toji Leon says:

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

Mustafa says:

Thanks for that interesting application. The Javascript works for me. But not the swf-file.