Last active
April 10, 2021 17:57
-
-
Save ouuan/6203b3db204fad54613a544735b817d2 to your computer and use it in GitHub Desktop.
Track time-usage for Xorg windows
This file contains hidden or 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
| #!/bin/bash | |
| file="$HOME/.track-window-stats" | |
| period=1 | |
| while true | |
| do | |
| locked=$(loginctl show-session "$XDG_SESSION_ID" -p LockedHint --value) | |
| if [[ "$locked" == 'yes' ]]; then | |
| result='<locked>' | |
| else | |
| focus="$(xprop -id $(xdotool getwindowfocus) | grep WM_CLASS | cut -f 4 -d'"')" | |
| if [[ -n "$focus" ]]; then | |
| result="$focus" | |
| else | |
| result='<empty>' | |
| fi | |
| fi | |
| time="$(date +%s)" | |
| if [[ "$result" == "$lastresult" ]]; then | |
| sed -i '$d' "$file" | |
| echo "$lasttime $((time - lasttime + period)) $result" >> "$file" | |
| else | |
| echo "$time $period $result" >> "$file" | |
| lasttime="$time" | |
| lastresult="$result" | |
| fi | |
| sleep "$period" | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment