Files
scripts/volume.sh

60 lines
1.4 KiB
Bash
Executable File

#!/usr/bin/env bash
readonly CURRENT_VOLUME_CMD='pactl get-sink-volume @DEFAULT_SINK@ | head -n 1 | cut -f 2 -d"/"'
readonly VOLUME_UP_CMD="pactl set-sink-volume @DEFAULT_SINK@ +5%"
readonly VOLUME_DOWN_CMD="pactl set-sink-volume @DEFAULT_SINK@ -5%"
readonly MUTE_CMD="pactl set-sink-mute @DEFAULT_SINK@ toggle"
readonly CHECK_MUTE_CMD="pactl get-sink-mute @DEFAULT_SINK@"
ACTION="$1"
check_if_active_notification () {
if makoctl list | grep -q -E 'Notification[[:space:]].*Volume'
then
makoctl list | grep -E 'Notification[[:space:]].*Volume' | cut -f 1 -d":" | cut -f 2 -d" "
fi
}
volume_up () {
eval "${VOLUME_UP_CMD}"
}
volume_down () {
eval "${VOLUME_DOWN_CMD}"
}
toggle_mute() {
eval "${MUTE_CMD}"
}
get_current_volume () {
# Check if mute first
mute=$(eval "${CHECK_MUTE_CMD}")
if [[ "$mute" == "Mute: yes" ]]; then
echo "Muted"
else
eval "${CURRENT_VOLUME_CMD}"
fi
}
send_notification () {
current_volume=$(get_current_volume)
active_notification=$(check_if_active_notification)
if [ -z "$active_notification" ]; then
notify-send -t 2000 "Volume" "${current_volume}"
else
notify-send -r ${active_notification} -t 2000 "Volume" "${current_volume}"
fi
}
if [[ "$ACTION" == "up" ]]; then
volume_up
send_notification
elif [[ "$ACTION" == "down" ]]; then
volume_down
send_notification
elif [[ "$ACTION" == "mute" ]]; then
toggle_mute
send_notification
fi