-
I've written a bash script to use within a custom module. I'm trying to use it as an infinite loop but the custom module never updates. The script should display the alsa volume. It waits on My script ( #!/bin/bash
# Loop forever
while : ; do
# Mangle the output of amixer into json
amixer get Master |
grep 'Mono:' |
sed --unbuffered -nre 's/.*\[off\].*/\{"text": " M x", "class": "muted", "percentage": 0\}/p'\
-e 's/.*\[(.*)%\].*/\{"text": "\1% ", "class": "unmuted", "percentage": \1\}/p'
# Wait until the next alsa event
/usr/sbin/alsactl monitor | grep -m 0 .
# Exit if alsactl monitor was interrupted
if (( ${PIPESTATUS[0]} != 141 )); then
break;
fi
done ) and my waybar config is "custom/alsa": {
"exec": "~/.config/waybar/volume.sh",
"return-type": "json",
"on-click": "amixer set Master toggle",
"on-scroll-up": "amixer set Master 5+",
"on-scroll-down": "amixer set Master 5-",
"tooltip": false
} On launch of waybar the custom module displays correctly, but it never updates. From a terminal
(this would be after 4 events) which, I believe is a sensible output for waybar. As such I expect the issue is with what form the output should take (this will be specific to waybar, potentially) or how the module is configured. If I remove the loop from I'm aware that some scripts buffer when not outputting to a terminal and so I've tried prefixing the call to Any ideas about why my custom waybar module's not updating? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
Why not remove the loop, just have your amixer line in your script and add signal and interval to your config? #!/bin/bash
amixer get Master | grep 'Mono:' |
sed --unbuffered -nre 's/.*\[off\].*/\{"text": " M x", "class": "muted", "percentage": 0\}/p'\
-e 's/.*\[(.*)%\].*/\{"text": "\1% ", "class": "unmuted", "percentage": \1\}/p' "custom/alsa": {
"exec": "~/.config/waybar/volume.sh",
"return-type": "json",
"signal": 1,
"interval": 1,
"on-click": "amixer set Master toggle",
"on-scroll-up": "amixer set Master 5+",
"on-scroll-down": "amixer set Master 5-",
"tooltip": false
} |
Beta Was this translation helpful? Give feedback.
-
Yes, that would work but relies on polling. As stated in the original post, I'm hoping to avoid this. I appreciate that avoiding polling is a "want" rather than a "need" but I'm confused as to why the elegant solution (waiting on |
Beta Was this translation helpful? Give feedback.
-
I have a working solution and so can guess at reasons! The working solution is
This reads one line at a time of the output from I expect this works because the pipe containing the output of |
Beta Was this translation helpful? Give feedback.
-
I have a similar problem with a script to display dwl's layout. Your mention of stdbuf helps me.
This is my simple script using dwlmsg, it watches dwl layout (ipc). The while loop works, without sed works, but using sed will not output anything on waybar. It does work on terminal:
And then I add |
Beta Was this translation helpful? Give feedback.
I have a working solution and so can guess at reasons!
The working solution is
This reads one line at a time of the output from
alsactl
, pumping the relevant info fromamixer
each time (and ignoring the line fromalsactl
). I also tweaked the sed line so that you could still see the volume when it was muted, but that's just co…