Last active
June 5, 2023 21:03
-
-
Save oltodosel/a6ad22ce85bb40018a8af4de41a6612b to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
# program-specific xbindkeys bindings | |
# there's a tool called `autokey`, which does this, but unlike xbindkeys, it doesn't catch mouse buttons | |
# doesn't interfere with main xbindkeys | |
# `pacman -S xbindkeys xdotool` | |
# `sleep 3 && cat /proc/$(xdotool getwindowpid $(xdotool getwindowfocus))/comm` | |
# create app-specific config file like $HOME/.scripts/xbindkeys_chromium.xk with standard xbindkeys config | |
# xbindkeys configs must be named xbindkeys_${app}.xk; xbindkeys_chromium.xk etc. | |
path_with_configs="$HOME/.scripts/" | |
########################################################### | |
declare -A apps | |
for zxc in $(ls ${path_with_configs}/xbindkeys*xk); do | |
apps[$(echo $zxc | sed 's/.*\///' | sed 's/\.xk$//' | sed 's/^xbindkeys_//')]=-1 | |
done; | |
last_date_in_s=0 | |
while : | |
do | |
current_proc=`cat /proc/$(xdotool getwindowpid $(xdotool getwindowfocus))/comm` || current_proc='DESKTOP' | |
if [[ $current_proc == $last_proc ]]; then | |
xev -root -event property | head -c1 >/dev/null | |
continue | |
fi | |
last_proc=$current_proc | |
idle_time=$(date -d @$(echo `date +%s` - $last_date_in_s | bc) -u +%H:%M) | |
if [[ $idle_time == '00:00' ]]; then | |
idle_time='-----' | |
fi | |
#' ' $(date -d @`echo \`xprintidle\` / 1000 | bc` +%H:%M) | |
echo `date|sed 's/EE.*//'` ' ' $idle_time ' ' $current_proc >> ~/.scripts/xbindkeys_LOG | |
# logging intervals more than 10 minutes | |
if [[ $(echo `date +%s` - $last_date_in_s | bc) -gt 10*60 ]]; then | |
echo `date|sed 's/EE.*//'` ' ' $idle_time ' ' $current_proc >> ~/.scripts/xbindkeys_LOG_10mp | |
fi | |
last_date_in_s=`date +%s` | |
for app in ${!apps[*]} | |
do | |
if [[ $current_proc = $app ]]; then | |
if [[ ${apps[$app]} = -1 ]]; then | |
xbindkeys -n -f "${path_with_configs}/xbindkeys_${app}.xk" & apps[$app]=$! | |
# dunstify -t 1111 ${app} | |
fi | |
elif [[ ${apps[$app]} != -1 ]]; then | |
kill ${apps[$app]} | |
apps[$app]=-1 | |
fi | |
done | |
xev -root -event property | head -c1 >/dev/null | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment