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


Update:

  1. Chris J Andrews made a JavaScript GUI frontend.

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


Comments

27 comments

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

Gravatar image Azmi
April 10th, 2007, 10:07 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 :)

Gravatar image Raghu
April 10th, 2007, 10:27 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)!

Gravatar image Rk
April 10th, 2007, 11:29 pm | #

[…] 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 […]

Gravatar image A Flexible Python is a deadly animal « FLEXing My Muscle
April 11th, 2007, 12:20 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

Gravatar image Abdul Qabiz
April 11th, 2007, 12:39 am | #

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

Gravatar image taj
April 11th, 2007, 2:48 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?

Gravatar image Prasun
April 11th, 2007, 4:16 am | #

Sexy :)

Gravatar image Anush
April 11th, 2007, 10:07 am | #

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?

Gravatar image Srikanth Thunga
April 11th, 2007, 11:30 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.

Gravatar image Philip
April 11th, 2007, 11:45 am | #

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.

Gravatar image t3rmin4t0r
April 11th, 2007, 2:29 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 …

Gravatar image Cédric Rabasse
April 11th, 2007, 3:34 pm | #

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

Gravatar image Pradeep
April 11th, 2007, 5:42 pm | #

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

Gravatar image Swaroop
April 12th, 2007, 1:23 am | #

Nice work.

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

Congratulations!

Gravatar image Domingo Aguilera
April 12th, 2007, 4:47 am | #

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

Gravatar image taggy
April 13th, 2007, 7:33 pm | #

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

Gravatar image Its My Life …… » Big Brother -2
April 14th, 2007, 2:12 pm | #

Hey, taggy did a Big Brother in ubunut(though it uses ltfx) Check http://freeshell.in/~taggy/blog

Gravatar image Allagappan
April 15th, 2007, 3:14 pm | #

the java GUI is not accessible . says Permission Denied

Gravatar image taggy
April 20th, 2007, 9:35 am | #

cool one! Its great!

Gravatar image Ranganath.S
April 20th, 2007, 1:38 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

Gravatar image Ranganath.S
April 20th, 2007, 2:56 pm | #

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

Gravatar image Calvin Spealman
April 22nd, 2007, 4:35 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’.

Gravatar image Swaroop
April 24th, 2007, 8:08 am | #

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.

Gravatar image Toji Leon
June 5th, 2007, 10:04 pm | #

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

Gravatar image Swaroop
June 6th, 2007, 7:25 am | #

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!

Gravatar image Toji Leon
June 6th, 2007, 12:07 pm | #

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

Gravatar image Mustafa
February 6th, 2008, 6:35 pm | #


Leave a Reply

Note: Comments can use Markdown syntax.

Policy on Comments : All comments will be moderated. Any off-topic comments will be deleted without notice.

Subscribe without commenting

About

Swaroop C H is 25 years of age. He graduated in B.E. (Computer Science) from PES Institute of Technology, Bangalore, India. He has previously worked at Yahoo! and Adobe.

More about

Books

  • A Byte of Python

    This book will help you to learn the Python programming language, even if all you know about computers is how to save text files.

    More info

Subscribe

If you want to know when new stories appear on this website, you can subscribe to the RSS feed or have them emailed to you:

RSS

Email

Enter your email address:

Microblogging

Twitter

del.icio.us articles

Waiting for next proto.in!

I'm attending Proto.in 2008 Delhi!

Advertisements

Photos