FollieHiyuki-dotfiles/home/.local/bin/volumecontrol

65 lines
1.8 KiB
Plaintext
Raw Normal View History

2021-02-13 11:28:59 -05:00
#!/bin/sh
if command -v mako >/dev/null
2021-02-13 11:28:59 -05:00
then
notification=mako
else
notification=dunst
2021-02-13 11:28:59 -05:00
fi
if command -v pulsemixer >/dev/null
then
_notify_volume() {
2021-02-13 11:28:59 -05:00
volume=$(pulsemixer --get-volume)
# 2 channels
left=$(echo "${volume}" | cut -d' ' -f1)
right=$(echo "${volume}" | cut -d' ' -f2)
notify-send -h string:x-canonical-private-synchronous:audio -h int:value:"${left}" -i "$HOME/.config/${notification}/speaker.png" "Volume: L:${left}% / R:${right}%"
2021-02-13 11:28:59 -05:00
}
case $1 in
increase)
pulsemixer --change-volume +5 && _notify_volume
2021-02-13 11:28:59 -05:00
;;
decrease)
pulsemixer --change-volume -5 && _notify_volume
2021-02-13 11:28:59 -05:00
;;
toggle)
pulsemixer --toggle-mute
status=$(pulsemixer --get-mute)
if [ "${status}" -eq 1 ] || [ "${status}" = "true" ]
2021-02-13 11:28:59 -05:00
then
notify-send -i "$HOME/.config/${notification}/mute.png" "Sound muted"
else
notify-send -i "$HOME/.config/${notification}/speaker.png" "Sound unmuted"
fi ;;
2021-02-13 11:28:59 -05:00
*)
;;
esac
else
_notify_volume() {
2021-02-13 11:28:59 -05:00
volume=$(amixer get Master | sed -nre 's/.*\\[(.*%)\\].*/\\1/p')
notify-send -h string:x-canonical-private-synchronous:audio -h int:value:"${volume}" -i "$HOME/.config/${notification}/speaker.png" "Volume: ${volume}"
2021-02-13 11:28:59 -05:00
}
case $1 in
increase)
amixer set Master 5+ && _notify_volume
2021-02-13 11:28:59 -05:00
;;
decrease)
amixer set Master 5- && _notify_volume
2021-02-13 11:28:59 -05:00
;;
toggle)
amixer set Master toggle
if amixer get Master | grep "off"
then
notify-send -i "$HOME/.config/${notification}/mute.png" "Sound muted"
else
notify-send -i "$HOME/.config/${notification}/speaker.png" "Sound unmuted"
fi ;;
2021-02-13 11:28:59 -05:00
*)
;;
esac
fi