Volume_brightness problem

I’m having an issue with the volume_brightness.sh script. I’m using i3wm and when I use my volume keys to adjust the volume, I’m not getting the notification from dunst that I usually do. However, the volume IS getting adjusted. I looked up the bindsym for the volume keys in ~/.config/i3/config and saw that it was using a script to display the volume changed using dunst. So, I ran the script in a terminal “~/.config/i3/scripts/volume_brightness.sh volume_up” and this was the output:

.config/i3/scripts/volume_brightness.sh: line 46: 4533 Segmentation fault (core dumped) dunstify -i audio-volume-muted-blocking -t 1000 -r 2593 -u normal “$volume_icon $volume%” -h int:value:$volume -h string:hlcolor:$bar_color

This is a recent issue/change and I have never touched this script myself.

Welcome to the community! :vulcan_salute: :enos_flag:

Please post the content of the script.

Use the button indicated below to format the script’s content properly for easier reading. Just select all of the content, then press the button or press CTRL+E instead.

1 Like
#!/bin/bash
# original source: https://gitlab.com/Nmoleo/i3-volume-brightness-indicator

# taken from here: https://gitlab.com/Nmoleo/i3-volume-brightness-indicator

# See README.md for usage instructions
bar_color="#7f7fff"
volume_step=1
brightness_step=2.5
max_volume=100

# Uses regex to get volume from pactl
function get_volume {
    pactl get-sink-volume @DEFAULT_SINK@ | grep -Po '[0-9]{1,3}(?=%)' | head -1
}

# Uses regex to get mute status from pactl
function get_mute {
    pactl get-sink-mute @DEFAULT_SINK@ | grep -Po '(?<=Mute: )(yes|no)'
}

# Uses regex to get brightness from xbacklight
function get_brightness {
    xbacklight | grep -Po '[0-9]{1,3}' | head -n 1
}

# Returns a mute icon, a volume-low icon, or a volume-high icon, depending on the volume
function get_volume_icon {
    volume=$(get_volume)
    mute=$(get_mute)
    if [ "$volume" -eq 0 ] || [ "$mute" == "yes" ] ; then
        volume_icon=""
    elif [ "$volume" -lt 50 ]; then
        volume_icon=""
    else
        volume_icon=""
    fi
}

# Always returns the same icon - I couldn't get the brightness-low icon to work with fontawesome
function get_brightness_icon {
    brightness_icon=""
}

# Displays a volume notification using dunstify
function show_volume_notif {
    volume=$(get_mute)
    get_volume_icon
    dunstify -i audio-volume-muted-blocking -t 1000 -r 2593 -u normal "$volume_icon $volume%" -h int:value:$volume -h string:hlcolor:$bar_color
}

# Displays a brightness notification using dunstify
function show_brightness_notif {
    brightness=$(get_brightness)
    get_brightness_icon
    dunstify -t 1000 -r 2593 -u normal "$brightness_icon $brightness%" -h int:value:$brightness -h string:hlcolor:$bar_color
}

# Main function - Takes user input, "volume_up", "volume_down", "brightness_up", or "brightness_down"
case $1 in
    volume_up)
    # Unmutes and increases volume, then displays the notification
    pactl set-sink-mute @DEFAULT_SINK@ 0
    volume=$(get_volume)
    if [ $(( "$volume" + "$volume_step" )) -gt $max_volume ]; then
        pactl set-sink-volume @DEFAULT_SINK@ $max_volume%
    else
        pactl set-sink-volume @DEFAULT_SINK@ +$volume_step%
    fi
    show_volume_notif
    ;;

    volume_down)
    # Raises volume and displays the notification
    pactl set-sink-volume @DEFAULT_SINK@ -$volume_step%
    show_volume_notif
    ;;

    volume_mute)
    # Toggles mute and displays the notification
    pactl set-sink-mute @DEFAULT_SINK@ toggle
    show_volume_notif
    ;;

    brightness_up)
    # Increases brightness and displays the notification
    xbacklight -inc $brightness_step -time 0 
    show_brightness_notif
    ;;

    brightness_down)
    # Decreases brightness and displays the notification
    xbacklight -dec $brightness_step -time 0
    show_brightness_notif
    ;;
esac

First thing, change

brightness_step=2.5

to

brightness_step=5

Based on the following: New volume_brightness.sh script brightness Problems


Second, try changing

dunstify -i audio-volume-muted-blocking -t 1000 -r 2593 -u normal "$volume_icon $volume%" -h int:value:$volume -h string:hlcolor:$bar_color

to

notify-send "Volume" "$volume_icon $volume%" -h int:value:$volume

or change

# Displays a volume notification using dunstify
function show_volume_notif {
    volume=$(get_mute)
    get_volume_icon
    dunstify -i audio-volume-muted-blocking -t 1000 -r 2593 -u normal "$volume_icon $volume%" -h int:value:$volume -h string:hlcolor:$bar_color
}

to

# Displays a volume notification using notify-send
function show_volume_notif {
    volume=$(get_mute)
    get_volume_icon
    notify-send -i audio-volume-muted -t 1000 "Volume" "$volume_icon $volume%" -h int:value:$volume -h string:x-canonical-private-synchronous:volume
}

As dunst should catch all notifications, the script shouldn’t need to specify dunst.

You may have to log out and log back in.

2 Likes

Thank you. That did work. This script was part of the default setup, though. Like, it was there as part of the fresh install I did when I first switched to Endeavour, and it did work for a long time. Should I file a bug report or something?

One of the devs or mods (@joekamprad) will probably see this post at some point. No need.

Please mark the post that solved your query as the solution. Glad I could help. :wink:

I do have one more question though. Using notify-send appears to add an extra volume icon. I see that there is a way to specify which icon to send with notify-send, is there a way to tell it not to send an icon at all? I’d prefer to just stick with the in-line icon since the script sets it dynamically by the volume level. Is there a way to tell notify-send not to include it’s icon? That would be more in line with how the notification appeared originally too.

Yeah, that is not ideal.

Which one did you actually use, by the way?

For the first, try:

notify-send "Volume" "$volume_icon $volume%" -h int:value:$volume -i "none"

And for the second, try:

function show_volume_notif {
    volume=$(get_mute)
    get_volume_icon
    notify-send -i "none" -t 1000 "Volume" "$volume_icon $volume%" -h int:value:$volume -h string:x-canonical-private-synchronous:volume
}
1 Like

I used the second one. I toyed around with it while I was waiting on a reply, though, and figured out that it would accept null as an argument for the -i option and just added that and it worked. Thank you though.

1 Like

we should go fix the script.

1 Like
1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.