Linux Shell Script / PulseAudio / Help Needed

Job ID: 37959306

Budget: $15 – $20 USD

I'm using a shell script to monitor for volume changes on Debian. The relevant code looks like this:

pactl subscribe | grep --line-buffered "sink" | while read -r UNUSED_LINE; do /home/user/.local/bin/showvolume.sh ; done;

This script worked fine on the first computer I used it on. However, on a second computer, it's not working well.

The problem seems to be that on the second computer, volume changes are detected twice. For example, when I click the "Volume Up" button on my keyboard, the initial 2 lines of output from command "pactl subscribe" are duplicates:
Event 'change' on sink #1
Event 'change' on sink #1

On the original computer, there was only one line of output for each "Volume Up" click. Note that both these computers have the same operating system (Debian 12), and I'm swapping the same keyboard between them.

So I need help with either:
1) How to prevent the duplicate "Event 'change' on sink #1" from happening,
or
2) How to modify this script so that it ignores any duplicate "Event 'change' on sink" detected within 1 second of each other.

Thanks for reading!
Related categories: Linux Shell Script Debian Bash Scripting