Volume bar script dunst

I found a volume bar script which have edited to suit my needs. Runs using amixer just a bit of bling really, but was fun getting it working .

2023-02-01-010632_319x74_scrot

sxhkdrc

# Media volume controls

XF86AudioRaiseVolume
    amixer set Master 5%+ && volume.sh up

XF86AudioLowerVolume
    amixer set Master 5%- && volume.sh down

XF86AudioMute
    amixer set Master toggle && volume.sh mute

volume.sh <<<< drop this in ~/.local/bin

#!/bin/bash

# You can call this script like this:
# $./volume.sh up
# $./volume.sh down
# $./volume.sh mute


device='default'    #audio device
interval='5'        #Percentage by which to update the volume
timeout='1'         #Notification timeout in seconds
bar_char="β– "        #Character to use for the volume bar
padding="    "      #Space to pad out the bar at the left of the notification

# The dunstify timeout is in milliseconds, so multiply our seconds setting by 1000
notify_timeout=$((timeout*8000))

#Icon settings
#Base for all icons, or you can specify the full path to each
icon_base="/usr/share/icons/Adwaita/32x32/status"
# Icon for when volume is changed
icon_audio_vol="$icon_base/audio-volume-high-symbolic.symbolic.png"
# Icon for when volume is muted
icon_audio_muted="$icon_base/audio-volume-muted-symbolic.symbolic.png"


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 off > /dev/null && amixer -q set Master unmute || amixer -q set Master mute
}

function send_notification {
    volume=$(get_volume)
    bar=$(seq -s "$bar_char" $((((volume / 5)+1))) | sed 's/[0-9]//g')
    # Send the notification
    dunstify -i "$icon_audio_vol" -t $notify_timeout -r 2593 -u normal "$padding$bar"
}

case $1 in
    up)
        # Set the volume on (if it was muted)
        amixer -D "$device" set Master on > /dev/null
        # Up the volume (+ $interval%)
        amixer -D "$device" sset Master $interval%+ > /dev/null
        send_notification
	;;
    down)
        amixer -D "$device" set Master on > /dev/null
        amixer -D "$device" sset Master $interval%- > /dev/null
        send_notification
	;;
    mute)
    	# Toggle mute
        amixer -D "$device" set Master 1+ toggle > /dev/null
        if is_mute ; then
            dunstify -t $notify_timeout -i "$icon_audio_muted" -r 2593 -u normal "Mute"
        else
            send_notification
        fi
    ;;
	esac
5 Likes

I think it should be like this?

timeout='8'         #Notification timeout in seconds

# The dunstify timeout is in milliseconds, so multiply our seconds setting by 1000
notify_timeout=$((timeout*1000))
1 Like

Just changed it from 1000 to 8000 so I would have time for the screenshot.

Will change timeout to this thanks for the heads up.

Just tested this `timeout=β€˜1’ not sure how it works but both are needed your it won’t work.

timeout='1'   #Notification timeout in seconds

# The dunstify timeout is in milliseconds, so multiply our seconds setting by 1000
notify_timeout=$((timeout*1000))