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:
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
BigBrother.pyandBigBrotherGUI.swfat the same time and watch the statistics.
And who said meetings aren’t productive
Update:
Chris J Andrews made a JavaScript GUI frontend.
Theyagarajan modified the Python script to make it work on Linux.






April 10th, 2007 at 10:07 pm
Man! do u still believe that you can do all your work without actually using a browser. Definitely not a case with me
April 10th, 2007 at 10:27 pm
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
April 10th, 2007 at 11:29 pm
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)!
April 11th, 2007 at 12:20 am
[...] 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 [...]
April 11th, 2007 at 12:39 am
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..
-abdul
April 11th, 2007 at 2:48 am
Next, detect the current tab in firefox so that you can track whether your browser is on a work-related page or not
April 11th, 2007 at 4:16 am
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?
April 11th, 2007 at 10:07 am
Sexy
April 11th, 2007 at 11:30 am
there is a bug! both at home and office, I only see orange color(firefox) in the whole graph
seriously speaking, cool app! why not make it a google desktop widget?
April 11th, 2007 at 11:45 am
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.
April 11th, 2007 at 2:29 pm
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.
April 11th, 2007 at 3:34 pm
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 …
April 11th, 2007 at 5:42 pm
@prasun, you need the chart library too. Trials version of which can be downloaded from the Flex site.
April 12th, 2007 at 1:23 am
@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_applicationfunction 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.
April 12th, 2007 at 4:47 am
Nice work.
It would be great if flash stuff would be generated by OpenLaszlo.
Congratulations!
April 13th, 2007 at 7:33 pm
is there a similar functionality in pygtk ? i would love to do a similar app for for my ubuntu box
April 14th, 2007 at 2:12 pm
[...] script for windows can be found at Swaroop`s blogTechnorati Tags: python, hack, [...]
April 15th, 2007 at 3:14 pm
Hey, taggy did a Big Brother in ubunut(though it uses ltfx) Check http://freeshell.in/~taggy/blog
April 20th, 2007 at 9:35 am
the java GUI is not accessible . says Permission Denied
April 20th, 2007 at 1:38 pm
cool one! Its great!
April 20th, 2007 at 2:56 pm
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
April 22nd, 2007 at 4:35 am
How does this work with apps that constantly change their titles, such as editors, winamp, firefox, etc.?
April 24th, 2007 at 8:08 am
@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’.
June 5th, 2007 at 10:04 pm
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 BigBrother.py=15,C:=5,Program Manager=5′
Windows XP SP2. Firefox 2.0.0.4.
June 6th, 2007 at 7:25 am
@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.
June 6th, 2007 at 12:07 pm
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 http://tinyurl.com/2z6j8t and http://tinyurl.com/25×69s
Disclaimer: This is the first time in my life that I look into an mxml file!
February 6th, 2008 at 6:35 pm
Thanks for that interesting application. The Javascript works for me. But not the swf-file.