Big Brother -2
Yesterday , i came across a script from swaroop`s blog which can track the amount of time you spend on each applications.But the script works only on windows and i looked around if i can put together a similar script for linux .
I initially tried using LDTP for it ,but i wanted only python and i came across ltfx which has get_active_win which returns the active window.
here is the script
#!/usr/bin/env python
import time,os,sys,commands
''' This Python script,will track how much time you spend on which application :) .It uses ltfx command . '''
''' License: http://www.opensource.org/licenses/bsd-license.php'''
''' ISSUES with the script: Identifying Terminal is a problem ,for eg, name of terminal can codelabs@delta/tmp ,in that case finding Terminal is not possible'''
''' URL for the script http://freeshell.in/~taggy/blog/work/ '''
total_counter = 0
counter = {}
_tick = 5 # Note which app is running, every `_tick` seconds
_refresh = 30 # Write out the file, every `_refresh` seconds
def get_title(title):
'''The commands.getstatusotput() returns a list ,list_name[1] contains the application Name”’
temp = title[1]
appln_name=temp.split(’-')[-1].strip()
print appln_name
return appln_name
def write_times_to_file(counter):
”’Write the time spent on each application to a file.”’
f = open(’HowMuchTimeYouWaste.txt’, ‘w’)
output = ‘n’.join(['%s=%s' % (app, counter[app]) for app in counter.keys()])
f.write(output)
f.close()
while True:
time.sleep(_tick)
cmd=”ltfx -e ‘get_active_win’ ”
print cmd
status = commands.getstatusoutput (cmd)
#print status
app = get_title( commands.getstatusoutput(cmd))
# print app
if app not in counter:
counter[app] = 0
counter[app] += _tick
total_counter += 1
if total_counter % (_refresh/_tick) == 0:
write_times_to_file(counter)
print counter # debug, remove if distracting
To get it running ,make sure you have ltfx installed,if not you can download it from here .
The script can also be downloaded from .
The script for windows can be found at Swaroop`s blog
Technorati Tags: python, hack, scripts
If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

Iam Theyagarajan S ( 'taggy') . to know more ,head out to

hey taggy ,
looks a neat script,just that it wont get Gnome Terminal or emacs ( emacs@filename) .some tweaking with it and i think it should be a lot useful .