diff --git a/polybar-scripts/pipewire-microphone/README.md b/polybar-scripts/pipewire-microphone/README.md index 73510d6c..e5412eac 100644 --- a/polybar-scripts/pipewire-microphone/README.md +++ b/polybar-scripts/pipewire-microphone/README.md @@ -6,7 +6,6 @@ A script for showing and toggling the mute state of the PipeWire default microph ## Dependencies * pactl (libpulse) -* pw-cat (pipewire) ## Module diff --git a/polybar-scripts/pipewire-microphone/pipewire-microphone.sh b/polybar-scripts/pipewire-microphone/pipewire-microphone.sh index 92e42a7f..9a4c77af 100644 --- a/polybar-scripts/pipewire-microphone/pipewire-microphone.sh +++ b/polybar-scripts/pipewire-microphone/pipewire-microphone.sh @@ -1,27 +1,15 @@ #!/bin/sh get_mic_default() { - pw-cat --record --list-targets | sed -n -E "1 s/^.*: (.*)/\1/p" + pactl info | awk '/Default Source:/ {print $3}' } is_mic_muted() { - mic_name="$(get_mic_default)" - - pactl list sources | \ - awk -v mic_name="${mic_name}" '{ - if ($0 ~ "Name: " mic_name) { - matched_mic_name = 1; - } else if (matched_mic_name && /Mute/) { - print $2; - exit; - } - }' + pactl get-source-mute "$(get_mic_default)" | awk '{print $2}' } get_mic_status() { - is_muted="$(is_mic_muted)" - - if [ "${is_muted}" = "yes" ]; then + if [ "$(is_mic_muted)" = "yes" ]; then printf "%s\n" "#1" else printf "%s\n" "#2" @@ -30,9 +18,8 @@ get_mic_status() { listen() { get_mic_status - LANG=EN; pactl subscribe | while read -r event; do - if printf "%s\n" "${event}" | grep --quiet "source" || printf "%s\n" "${event}" | grep --quiet "server"; then + if printf "%s\n" "${event}" | grep -qE '(source|server)'; then get_mic_status fi done @@ -42,7 +29,7 @@ toggle() { pactl set-source-mute @DEFAULT_SOURCE@ toggle } -case "$1" in +case "${1}" in --toggle) toggle ;;