Last active
December 18, 2015 21:09
-
-
Save cyrus-and/5845016 to your computer and use it in GitHub Desktop.
Track the time spent on X11 applications
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# Track the time spent on X11 applications. | |
# | |
# Dependencies: coreutils x11-utils xprintidle | |
# | |
# Usage: | |
# | |
# $ deprocrastinator > out.log # 1. record | |
# $ deprocrastinator out.log # 2. analyze | |
# | |
INACTIVITY=5000 | |
SLOT=1 | |
if [ $# = 1 ] ; then | |
if [ -r $1 ] ; then | |
LOG=$1 | |
APPS=$(cat $LOG | cut -d $'\x00' -f 1 | sort | uniq -c | sort -rn | sed 's/^ \+/\t/') | |
TOP=$(cat $LOG | cut -d $'\x00' -f 2 | sort | uniq -c | sort -rn | head -n 10 | sed 's/^ \+/\t/') | |
echo "[Overall]" | |
echo | |
echo "$APPS" | |
echo | |
echo "[Top]" | |
echo | |
echo "$TOP" | |
echo | |
echo "[Detail]" | |
for i in $(echo -n "$APPS" | awk '{ print $2 }') ; do | |
echo | |
echo " $i" | |
echo | |
grep --binary-files=text -e "^$i"$'\x00' $LOG | cut -d $'\x00' -f 2 | sort | uniq -c | sort -rn | sed 's/^ \+/\t\t/' | |
done | |
fi | |
else | |
while sleep $SLOT; do | |
if [ $(xprintidle) -lt $INACTIVITY ]; then | |
ID=$(xprop -root _NET_ACTIVE_WINDOW); ID=${ID//*# } | |
if [ "$ID" != "0x0" ] ; then | |
NAME=$(xprop _OB_APP_CLASS -id "$ID"); NAME=${NAME//*= } | |
TITLE=$(xprop _NET_WM_NAME -id "$ID"); TITLE=${TITLE//*= } | |
echo -e "$NAME\x00$TITLE" | |
fi | |
fi | |
done | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment