From e8e3ac08ffc19db72fb63c8b3ef7f41e14aaff9e Mon Sep 17 00:00:00 2001 From: allddd <117767298+allddd@users.noreply.github.com> Date: Sat, 4 Nov 2023 15:14:06 +0100 Subject: [PATCH] fix #436 --- .../pipewire-microphone.sh | 43 +++++++------------ 1 file changed, 16 insertions(+), 27 deletions(-) diff --git a/polybar-scripts/pipewire-microphone/pipewire-microphone.sh b/polybar-scripts/pipewire-microphone/pipewire-microphone.sh index 92e42a7f..d324bb84 100644 --- a/polybar-scripts/pipewire-microphone/pipewire-microphone.sh +++ b/polybar-scripts/pipewire-microphone/pipewire-microphone.sh @@ -1,52 +1,41 @@ #!/bin/sh -get_mic_default() { - pw-cat --record --list-targets | sed -n -E "1 s/^.*: (.*)/\1/p" +_get_mic_default() { + 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; - } - }' +_is_mic_muted() { + pactl get-source-mute "$(_get_mic_default)" | awk '{print $2}' } -get_mic_status() { - is_muted="$(is_mic_muted)" - - if [ "${is_muted}" = "yes" ]; then +_get_mic_status() { + if [ "$(_is_mic_muted)" = "yes" ]; then printf "%s\n" "#1" else printf "%s\n" "#2" fi } -listen() { - 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 - get_mic_status + if printf "%s\n" "${event}" | grep -qE '(source|server)'; then + _get_mic_status fi done } -toggle() { +_toggle() { pactl set-source-mute @DEFAULT_SOURCE@ toggle } -case "$1" in +case "${1}" in --toggle) - toggle + _toggle ;; *) - listen + _listen ;; esac + +# vim: ts=4 sw=4 et: