Skip to content

Instantly share code, notes, and snippets.

@dnisyd
Created August 7, 2019 19:06
Show Gist options
  • Save dnisyd/f52497045fa8a7c1f35402ec86f00932 to your computer and use it in GitHub Desktop.
Save dnisyd/f52497045fa8a7c1f35402ec86f00932 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# You can call this script like this:
# $ ./volumeControl.sh up
# $ ./volumeControl.sh down
# $ ./volumeControl.sh mute
# Script modified from these wonderful people:
# https://github.com/dastorm/volume-notification-dunst/blob/master/volume.sh
# https://gist.github.com/sebastiencs/5d7227f388d93374cebdf72e783fbd6a
id=2593
function get_volume {
amixer get Master | grep '%' | head -n 1 | cut -d '[' -f 2 | cut -d '%' -f 1
}
function is_audio_mute {
amixer get Master | grep '%' | grep -oE '[^ ]+$' | grep off > /dev/null
}
function is_mic_mute {
amixer get Capture | grep off > /dev/null
}
function send_notification {
iconSound="audio-volume-high"
iconMuted="audio-volume-muted"
if is_audio_mute ; then
dunstify -t 1000 -i $iconMuted -r $id -u normal "AUDIO: MUTE"
else
volume=$(get_volume)
# Make the bar with the special character ─ (it's not dash -)
# https://en.wikipedia.org/wiki/Box-drawing_character
#bar=$(seq --separator="█" 0 "$((volume / 5))" | sed 's/[0-9]//g')
# Send the notification
dunstify -t 1000 -i $iconSound -r $id -u normal "VOLUME: $volume% "
fi
}
function send_mic_notification {
icon="audio-input-microphone"
if is_mic_mute ; then
dunstify -t 1000 -i $icon -r $id -u normal "MICROPHONE: MUTE "
else
dunstify -t 1000 -i $icon -r $id -u normal "MICROPHONE: ON "
fi
}
case $1 in
up)
# set the volume on (if it was muted)
amixer -D pulse set Master on > /dev/null
# up the volume (+ 5%)
amixer -D pulse sset Master 5%+ > /dev/null
send_notification
;;
down)
amixer -D pulse set Master on > /dev/null
amixer -D pulse sset Master 5%- > /dev/null
send_notification
;;
toggle)
# toggle audio
amixer -D pulse set Master toggle > /dev/null
send_notification
;;
mic)
# toggle mic
amixer -D pulse set Capture toggle > /dev/null
send_mic_notification
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment