Skip to content

Instantly share code, notes, and snippets.

@adamzwakk
Forked from sebastiencs/volume.sh
Last active October 30, 2018 02:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamzwakk/b6efc1498976099f37d2f22bac8b44ec to your computer and use it in GitHub Desktop.
Save adamzwakk/b6efc1498976099f37d2f22bac8b44ec to your computer and use it in GitHub Desktop.
Script to get volume notification with dunst http://imgur.com/a/qWgAw
#!/bin/bash
# You can call this script like this:
# $./volume.sh up
# $./volume.sh down
# $./volume.sh mute
function get_volume {
amixer get Master | grep '%' | head -n 1 | cut -d '[' -f 2 | cut -d '%' -f 1
}
function is_mute {
amixer get Master | grep '%' | grep -oE '[^ ]+$' | grep off > /dev/null
}
function send_notification {
volume=`get_volume`
# Make the bar with the special character ─ (it's not dash -)
# https://en.wikipedia.org/wiki/Box-drawing_character
bar=$(seq -s "─" $(($volume / 5)) | sed 's/[0-9]//g')
# Send the notification
notify-send "$volume% $bar" -i multimedia-volume-control -t 5000 -r 1000
}
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
;;
mute)
# Toggle mute
amixer -D pulse set Master 1+ toggle > /dev/null
if is_mute ; then
dunstify -i audio-volume-muted -t 8 -r 2593 -u normal "Mute"
else
send_notification
fi
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment