LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Blogs > linux-related notes
User Name
Password

Notices


Just annotations of little "how to's", so I know I can find how to do something I've already done when I need to do it again, in case I don't remember anymore, which is not unlikely. Hopefully they can be useful to others, but I can't guarantee that it will work, or that it won't even make things worse.
Rate this Entry

Bash script that pops-up notification with a bar graph of where you're spending your time on PC

Posted 03-02-2020 at 08:14 PM by the dsc
Updated 03-02-2020 at 08:16 PM by the dsc

Preliminary but works, even though I'm probably doing some stuff wrong/dumbly. Basically, "if input is idle for less than two minutes, then grep the active window, if it's the same active window for two times in three 30-second time-windows, count it as active ; after looping N times, show a rudimentary bar graph of how many times each logged window was used."

It would be nicer to actually transform the counting of each program in a percentage of the total, but it's good enough for now.

No copyrights whatsoever and all that FOSS stuff. It depends at least on xprintidle, xdotool, and notify-send.

Code:
#!/bin/bash

log=/dev/shm/timespent.log

while true ; do 

if (( $(xprintidle) < 30000 )) ; then

win1=$( xdotool getactivewindow getwindowname | sed 's|.*\ -\ ||' )

sleep 30

win2=$( xdotool getactivewindow getwindowname | sed 's|.*\ -\ ||' )

sleep 30

win3=$( xdotool getactivewindow getwindowname | sed 's|.*\ -\ ||' )

            if [[ "$win1" == "$win2" ]] ; then 

            echo $win1 >> $log

            elif [[ "$win1" == "$win3" ]] ; then

            echo $win1 >> $log

            elif [[ "$win2" == "$win3" ]] ; then 

            echo $ $win2 >> $ log

            fi

loop=$((loop+1))

        if ((loop==8)) ; then

 sed -ie 's|.*/|xterm-|g;s|xterm-.*|xterm|g' $log

   sort -u $log | while read prog ; do 
                progcount=$(grep $prog $log | wc -l)

                if [[ -z "$parse" ]] ; then
                bar=$"$(for n in $(seq 1 $progcount) ; do printf "█" ; done)"
                parse="${prog}\t${bar}" 
        
        else

                bar=$"$(for n in $(seq 1 $progcount) ; do printf "█" ; done)"
                parse="${parse}\n${prog}\t${bar}"

                fi
echo $parse > /dev/shm/parse
                done


        notify-send "Time spent" "$(cat /dev/shm/parse)" -t 5000
loop=0



        fi
        
fi

sleep 30

done
Posted in Uncategorized
Views 2975 Comments 0
« Prev     Main     Next »
Total Comments 0

Comments

 

  



All times are GMT -5. The time now is 07:32 AM.

Main Menu
Advertisement
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration