All pastes #1903214 Raw Edit

idlelog.sh

public shellscript v1 · immutable
#1903214 ·published 2010-07-18 21:59 UTC
rendered paste body
#!/bin/bashthreshold=300 # how many seconds to consider idlegoneidle=0while sleep 1;do  idleplus=$(xidles)  if [ $idleplus -ge $threshold ];then    if [ $goneidle -eq 0 ];then      goneidle=1      nowtime=$(date +%s)      idletime=$((nowtime-idleplus))      echo "went idle @ $(localtime $idletime)" >>~/.idlelog    fi  else    if [ $goneidle -gt 0 ];then      goneidle=0      nowtime=$(date +%s)      returntime=$((nowtime-idleplus))      gonefor=$(printf $((returntime-idletime)) | awk '{printf \        "%id %2ih %2im %2is",($1/3600/24),($1/3600%24),($1/60%60),($1%60)}')      echo "came back @ $(localtime $returntime) ($gonefor)" >>~/.idlelog    fi  fidone