I would like to configure i3WM to set maximum volume level (let's say 150%) so I won't accidentally increase volume to some huge value. I made bash script which execution is binded to volume_up key. All elements work fine separatedly, but when I put everything together, there is something wrong.
Bash script code:
#!/bin/bash
max_volume_pc=$1
current_volume_pc=$(pactl list sinks | grep '^[[:space:]]Volume:' | head -n $(( $SINK + 1 )) | tail -n 1 | sed -e 's,.* \([0-9][0-9]*\)%.*,\1,')
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
bind in i3 config file:
bindsym XF86AudioRaiseVolume exec ~/.config/i3/custom_configs/volume_up.sh 150
What works just fine:
- voluming up when binded is just a single command for increasing volume with pactl (without any bash script, just exec pactl command in i3 config file same as command in if statement above)
- executing only the above bash script from terminal
- executing everything together, but when
current_volume_pc
is hard coded to some value
So everything points to issue with getting current volume value when script is executed through key-binded action, but I have no idea how to fix it. There is also no error comunicate from i3 and my OS is Ubuntu 20.04, if these informations would be helpful to someone. I also tried some other ways of binding syntax, but the result is always the same and syntax provided above seems most logic to me.
I also found reddit with similar question here: https://www.reddit.com/r/i3wm/comments/dens5j/limiting_pulseaudio_max_volume/, but I don't understand what is happening in dikduk's file and I think it's better for me to find help with fixing my own issue rather than copy-pasting someone's solution