2024-02-01 04:20:58 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
LOCK=/tmp/volume-lock
|
|
|
|
if [ -e $LOCK ]; then
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
touch $LOCK
|
|
|
|
|
|
|
|
SINK=$(pactl get-default-sink)
|
|
|
|
|
|
|
|
if [ -z $1 ]; then
|
|
|
|
ACTION="get-sink-volume $SINK"
|
|
|
|
elif [ $1 == 'up' ]; then
|
|
|
|
ACTION="set-sink-volume $SINK +1%"
|
|
|
|
elif [ $1 == 'down' ]; then
|
|
|
|
ACTION="set-sink-volume $SINK -1%"
|
|
|
|
else
|
|
|
|
echo "Invalid argument $1"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -e /tmp/volume-notification ]; then
|
|
|
|
NOTIFY_ID=$(cat /tmp/volume-notification)
|
|
|
|
if [ -z /tmp/volume-notification ]; then
|
|
|
|
rm /tmp/volume-notification
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
VOLUME=$(pactl get-sink-volume $SINK | grep Volume | sed -r 's/.* (1?[0-9]?[0-9])% \/.*/\1/')
|
|
|
|
if [[ $ACTION != "set-sink-volume $SINK +1%" ]] && [[ $VOLUME -eq 0 ]]; then
|
2024-03-08 19:11:04 +00:00
|
|
|
echo $VOLUME > ${HOME}/.local/state/last_volume
|
2024-02-01 04:20:58 +00:00
|
|
|
elif [[ $ACTION != "set-sink-volume $SINK -1%" ]] && [[ $VOLUME -eq 150 ]]; then
|
2024-03-08 19:11:04 +00:00
|
|
|
echo $VOLUME > ${HOME}/.local/state/last_volume
|
2024-02-01 04:20:58 +00:00
|
|
|
elif [[ $ACTION != "get-sink-volume $SINK" ]]; then
|
|
|
|
pactl $ACTION
|
|
|
|
VOLUME=$(pactl get-sink-volume $SINK | grep Volume | sed -r 's/.* (1?[0-9]?[0-9])% \/.*/\1/')
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ $VOLUME -eq 0 ]]; then
|
|
|
|
ICON='-off'
|
|
|
|
elif [[ $VOLUME -le 34 ]]; then
|
|
|
|
ICON='-low'
|
|
|
|
elif [[ $VOLUME -le 67 ]]; then
|
|
|
|
ICON='-medium'
|
|
|
|
else
|
|
|
|
ICON='-high'
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -z $NOTIFY_ID ]]; then
|
|
|
|
NOTIFY_ID=$(notify-send --category=volume --urgency=low --hint=int:value:$VOLUME --icon=${HOME}/.icons/Gruvbox/48x48@2x/devices/notification-audio-volume${ICON}.svg -p -t 1000 Volume ${VOLUME}%)
|
|
|
|
else
|
|
|
|
NOTIFY_ID=$(notify-send --category=volume --urgency=low --hint=int:value:$VOLUME --icon=${HOME}/.icons/Gruvbox/48x48@2x/status/notification-audio-volume${ICON}.svg -p -r $NOTIFY_ID -t 1000 Volume ${VOLUME}%)
|
|
|
|
fi
|
|
|
|
|
|
|
|
VOLUME=$(pactl get-sink-volume $SINK | grep Volume | sed -r 's/.* (1?[0-9]?[0-9])% \/.*/\1/')
|
|
|
|
echo $NOTIFY_ID > /tmp/volume-notification
|
2024-03-08 19:11:04 +00:00
|
|
|
echo $VOLUME > ${HOME}/.local/state/last_volume
|
2024-02-01 04:20:58 +00:00
|
|
|
rm /tmp/volume-lock
|