While analyzing @muzqs solution I realized there is a scenario where you can have more than 100% volume. (my system, for example, gives up to 150% [meaning 1.50 decimal]). Then, I came up with this follow up:
Edit: fixed in order to detect the muted case. Thank you @muzqs
#!/bin/bash
vol="$(wpctl get-volume @DEFAULT_AUDIO_SINK@ \
| awk '{if (NF==3) {print "00"} else {split($2,a,"."); if (a[1] != 1) {print a[2]} else {print a[1]a[2]}}}')"
case $vol in
00 ) vol_icon="婢" ;; # cero volume or muted
0[1-9]|[1-2][0-9] ) vol_icon="奄" ;; # 01-29
[3-6][0-9] ) vol_icon="奔" ;; # 30-69
* ) vol_icon="墳" ;; # any other (70+) is max volume
esac
echo "${vol_icon}<sup><span size='xx-small'> $vol%</span></sup>"
You were right. You can have X volume and still being mute. My first approach was just moving the volume slider but not muting the output.
The change was to count Fields (NF variable) inside AWK; only when muted has a value of 3. I did it on purpose in order to avoid a language depending solution.
Its quit a chalange to find a solution for over 100% loudeness with wpctl.
Reading different posts around the net.
Cannot find a solution against over 100% volume yet.
I tested it how high i could get with volume. My amp volume very low.
It feels not right to do and it isn’t, but still it goes controled in little steps.
For me the main issue was that the icon went on mute when i ran bluetooth audio. Volume icon didn’t showing other volume %.
With wpctl the icon stays.
I suspect how the output is given when more than one sink running.
Using pactl - 2 versions
version 1 - Default audio sink on when mute is off .
output mute status
Mute : no
$ no
Volume icon shown fine.
version 2 - output mute off status with bluetooth on.
output mute status 2 sinks running
Mute : no
Mute : no
$ no
$ no
Volume icon not shown.
It gives more then one no.
I am quessing the script can only handle one output as result.
For now i am fine, i think, overcoming the volume overkill thing.
It get’s the right value for mute to manage icons.
Independed how many sinks running.
I can run bluetooth or/and jamesdsp without icon issues.
For the volumettf icon management.
Iam trying to stay close with the original.
And i use another volume icon.
This has about 8 different icons.
if [[ $vol -ge 80 ]]; then
echo "⣟<sup><span size='xx-small'> $vol%</span></sup>"
elif [[ $vol -ge 70 ]]; then
echo "⣏<sup><span size='xx-small'> $vol%</span></sup>"
elif [[ $vol -ge 60 ]]; then
echo "⣇<sup><span size='xx-small'> $vol%</span></sup>"
elif [[ $vol -ge 50 ]]; then
echo "⣃<sup><span size='xx-small'> $vol%</span></sup>"
elif [[ $vol -ge 30 ]]; then
echo "⣂<sup><span size='xx-small'> $vol%</span></sup>"
elif [[ $vol -ge 10 ]]; then
echo "⣀<sup><span size='xx-small'> $vol%</span></sup>"
elif [[ $vol -ge 0 ]]; then
echo "X<sup><span size='xx-small'> $vol%</span></sup>"
else