Set max limit for volume increase with i3, pactl and bash
Solution 1:
I found the issue. It was caused by my system language - I'm from Poland, so I set Polish to my system language, but I changed terminal language in .bashrc to English because it's more convinient.
In my case, when I executed my bash script directly from terminal, I got result of pactl list sinks
in English (I assume due to .bashrc language change), so everything worked just fine. But when I executed script using key binding, the result I got from above command was in Polish, so grep couldn't find 'Volume' word. I'm putting correct bash script that works both when calling from terminal or key binding below if anyone would had similar problem.
#!/bin/bash
max_volume_pc=$1
current_volume_pc=$(pactl list sinks | grep '<Your system language word that means "volume">' | head -n $(( $SINK + 1 )) | tail -n 1 | sed -e 's,.* \([0-9][0-9]*\)%.*,\1,')
if (($(echo -n $current_volume_pc | wc -m) == 0)); then
current_volume_pc=$(pactl list sinks | grep '^[[:space:]]Volume:' | head -n $(( $SINK + 1 )) | tail -n 1 | sed -e 's,.* \([0-9][0-9]*\)%.*,\1,')
fi
if (($current_volume_pc < $max_volume_pc-10)) ; then
pactl set-sink-volume @DEFAULT_SINK@ +10% && $refresh_i3status
else
a=$(($max_volume_pc - $current_volume_pc))
pactl set-sink-volume @DEFAULT_SINK@ +$a% && $refresh_i3status
fi