#!/bin/bash # You can call this script like this: # $./volume.sh up # $./volume.sh down # $./volume.sh mute function get_volume { pamixer --get-volume | cut -d '%' -f 1 } function is_mute { pamixer --get-mute | grep true > /dev/null } function send_notification { DIR=`dirname "$0"` 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') if [ "$volume" = "0" ]; then icon_name="/usr/share/icons/breeze-dark/status/24@2x/audio-volume-muted.svg" notify-vol-send -a "Volume" "$volume"" " -i "$icon_name" -t 2000 -h int:value:"$volume" -h string:synchronous:"─" --replace=555 else if [ "$volume" -lt "10" ]; then icon_name="/usr/share/icons/breeze-dark/status/24@2x/audio-volume-low.svg" notify-vol-send -a "Volume" "$volume"" " -i "$icon_name" --replace=555 -t 2000 else if [ "$volume" -lt "30" ]; then icon_name="/usr/share/icons/breeze-dark/status/24@2x/audio-volume-low.svg" else if [ "$volume" -lt "70" ]; then icon_name="/usr/share/icons/breeze-dark/status/24@2x/audio-volume-medium.svg" else icon_name="/usr/share/icons/breeze-dark/status/24@2x/audio-volume-high.svg" fi fi fi fi bar=$(seq -s "─" $(($volume/5)) | sed 's/[0-9]//g') # Send the notification notify-vol-send -a "Volume" "$volume"" " -i "$icon_name" -t 2000 -h int:value:"$volume" -h string:synchronous:"$bar" --replace=555 } case $1 in up) # Set the volume on (if it was muted) pamixer -u > /dev/null # Up the volume (+ 5%) pamixer -i 5 > /dev/null send_notification ;; down) pamixer -u > /dev/null pamixer -d 5 > /dev/null send_notification ;; mute) # Toggle mute pamixer -m > /dev/null if is_mute ; then DIR=`dirname "$0"` notify-vol-send -a "Volume" -i "/usr/share/icons/breeze-dark/status/24@2x/audio-volume-muted.svg" --replace=555 -u normal "Mute" -t 2000 else send_notification fi ;; esac