ArchLabs Linux

Output blinking in polybar... possible?

hello fellows, I’d like to get some scripts output blinking in polybar as they do in the terminal, for example the updates notification. My script is:

#!/bin/sh

if ! updates_arch=$(checkupdates 2> /dev/null | wc -l ); then
    updates_arch=0
fi

# if ! updates_aur=$(yay -Qum | wc -l); then
# if ! updates_aur=$(cower -u 2> /dev/null | wc -l); then
if ! updates_aur=$(trizen -Su --aur --quiet | wc -l); then
    updates_aur=0
fi

updates=$(("$updates_arch" + "$updates_aur"))

if [ "$updates" -gt 0 ]; then
    echo -e "\e[5m$updates"
else
    echo "0"
fi

But unfortunatly it doesn’t work in polybar. Any suggestion ?

Blinking is something supported by most terminal emulators but isn’t standard for text input like this, polybar is free to ignore any sequences it wants.

You can get a similar effect using sleep and multiple echo to clear and reprint

echo text
sleep 0.5
echo
sleep 0.5
echo text
...

The output I get is \e[5m6 but I’m expecting 6 where 6 is the number of updates.
Shellcheck returns no error about the script.

So you tried replacing the escape sequence echo with my above suggestion?

Yes I’ve tried the sleep sequences but no expected result, in fact the module crashed :laughing: so maybe I should ask the polybar dev for that comestic aspect :lipstick:, thanks anyway.
I have found this discussion Blinking format tag so maybe one day…

I’ll install polybar and make a small example with blinking tonight and post it here.

1 Like

I appriciate :slightly_smiling_face: but I’ll see your post tomorrow because of our locations.

module:

[module/blink]
type = custom/script
label = %output%
label-padding = 2
interval = 10
tail = true
exec = ~/.config/polybar/test.sh

script:

#!/bin/bash

if (( (count=$(checkupdates 2>/dev/null | wc -l)) > 0 )); then
	while :; do
		printf "%d\n" $count
		sleep 0.3
		printf "%*s\n" ${#count} # number of characters to fill with spaces to stop bar contents shifting
		sleep 0.3
	done
else
	printf "\n"
fi

example in use:
polybar-example

1 Like

Hello nate, first of all thank you for your help. I think your solution is good but I’m going to increase the interval with polybar ipc hooks once an hour or so because of cpu (while loop) and network requests over archlinux server (I don’t want to be banned) :joy: .

Hi @natemaia, after updating it does not turn off the blink,why?

My post was not something anyone should use, just an example of blinking text.

If you want something similar but actually usable you can modify your existing module with the blinking example.