This script logs to a file the name of the active windows, so you can keep track of how much time you spend on each activity.
It logs only the current session, if you modify it, please post the results :-)
If you use firefox, you need to install the "nightly tester tools" adddon to change the title of the window to "firefox", otherwise the script will keep track of each url visited.
Currently I embed the resulting text file in conky, it updates only each minute, to prevent writing too often to the disk; maybe there is a way to "pipe" the results to conky.
use feature ':5.10'; # loads all features available in perl 5.10
use IPC::System::Simple qw(system systemx capture capturex);
while (1)
{
$comando =
q(xprop -root | grep "_NET_ACTIVE_WINDOW(WINDOW)"| cut -d ' ' -f
+ 5);
$output = capture("$comando");
chomp $output;
$titolo =
q(xwininfo -id )
. $output
. q( |awk 'BEGIN {FS="\""}/xwininfo: Window id/{print $2}' | sed
+ 's/-[^-]*$//g');
$outTitolo = capture("$titolo");
chomp $outTitolo;
sleep 60;
if ( $outTitolo =~ /firefox/gsi ) {
$outTitolo = 'firefox';
}
push( @myNames, $outTitolo );
my %hashActivity = count_unique(@myNames);
undef my $oreTotali;
while ( my ( $key, $value ) = each(%hashActivity) ) {
$oreTotali = $value + $oreTotali;
}
open FILE, ">.activityLog.txt" or die $!;
print FILE " $oreTotali minuti Uptime ";
foreach $key ( sort { $hashActivity{$b} <=> $hashActivity{$a} }
keys %hashActivity )
{
$percentualeOre = int( $hashActivity{$key} / $oreTotali * 100
+);
print FILE "\n $hashActivity{$key}\' $key\n ";
for ( 0 .. $percentualeOre / 10 ) {print FILE "=="}
print FILE " $percentualeOre \%";
}
print FILE "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
}
sub count_unique {
my @array = @_;
my %count;
map { $count{$_}++ } @array;
#print them out:
# map {print "$_ = ${count{$_}}\n"} sort keys(%count);
#or just return the hash:
return %count;
}