Show a notification when recording device changes

This commit is contained in:
elenapan 2025-04-01 16:40:21 +03:00
parent feb0452d5e
commit 5fa6aad8dd

View file

@ -1,8 +1,17 @@
#!/bin/bash
#!/usr/bin/env bash
old_source=$(pactl get-default-source)
old_status=-1
update() {
info="$(pactl list sources | awk '/Name: alsa_input.pci/{nr[NR+6]}; NR in nr')"
default_source=$(pactl get-default-source)
info="$(pactl get-source-mute "$default_source")"
status="$([[ "$info" == *"Mute: yes"* ]] && echo off || echo on)"
if [[ "$default_source" != "$old_source" ]]; then
device=$(pactl list sources | awk '/Name: '$default_source'/{nr[NR+1]}; NR in nr {print substr($0, index($0, $2))}')
notify-send.sh -R /tmp/recording-device-notification --urgency low "Recording device" "$device"
old_source="$default_source"
fi
# Only update if status changed
if [ "$old_status" != "$status" ]; then
eww update microphone="$status"
@ -15,18 +24,6 @@ if [ "$1" == "oneshot" ]; then
exit
fi
LANG=C pactl subscribe 2> /dev/null | grep --line-buffered "Event 'change' on source #" | while read -r line ; do
LANG=C pactl subscribe 2> /dev/null | grep --line-buffered "source #" | while read -r line ; do
update
done
# ------ Before pipewire
# update() {
# info="$(pacmd list-sources | awk '/\\* index: /{nr[NR+7];nr[NR+11]}; NR in nr' | tail -1)"
# muted="$([[ "$info" == *"muted: yes"* ]] && echo '' || echo active)"
# eww update microphone="$muted"
# }
# update
# pactl subscribe 2> /dev/null | grep --line-buffered "source #" | while read -r line ; do
# update
# done