Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- muteTimeMS=200
- echo 0 > .lastKPTime
- checkKeyPress() {
- echo "capturing input"
- xinput test-xi2 --root | grep --line-buffered RawKeyPress |
- while read -r line; do
- lastPressTime=`cat .lastKPTime`
- deviceID=`pactl list short sources | grep RUNNING | head -n 1 | cut -f1`
- muted=$(pactl list sources | grep '^[[:space:]]Mute:' | head -n $deviceID | tail -n 1 | xargs | cut -d':' -f2 | xargs)
- # Skip if the user has muted themsevles
- if [ "${lastPressTime}" = "0" ] && [ "$muted" = "yes" ]; then
- continue
- fi
- echo `date +%s%N | cut -b1-13` > .lastKPTime
- if [ $muted = "yes" ]; then
- continue
- fi
- pactl set-source-mute $deviceID true
- echo "muted"
- done
- }
- checkKeyPress &
- while true
- do
- sleep .1
- deviceID=`pactl list short sources | grep RUNNING | head -n 1 | cut -f1`
- muted=$(pactl list sources | grep '^[[:space:]]Mute:' | head -n $deviceID | tail -n 1 | xargs | cut -d':' -f2 | xargs)
- if [ $muted != "yes" ]; then
- continue
- fi
- lastPressTime=`cat .lastKPTime`
- if [ "${lastPressTime}" = "0" ]; then
- continue
- fi
- currentTimeMS=`date +%s%N | cut -b1-13`
- timeSinceLastKP=`expr $currentTimeMS - $lastPressTime`
- if (( timeSinceLastKP > $muteTimeMS )); then
- pactl set-source-mute $deviceID false
- echo "unmuting"
- echo 0 > .lastKPTime
- fi
- done
Advertisement
Add Comment
Please, Sign In to add comment