Skip to content

Commit

Permalink
pipewire-microphone: replace pw-cat
Browse files Browse the repository at this point in the history
  • Loading branch information
allddd authored Nov 6, 2023
1 parent d902586 commit 8798346
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 19 deletions.
1 change: 0 additions & 1 deletion polybar-scripts/pipewire-microphone/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 5 additions & 18 deletions polybar-scripts/pipewire-microphone/pipewire-microphone.sh
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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
Expand All @@ -42,7 +29,7 @@ toggle() {
pactl set-source-mute @DEFAULT_SOURCE@ toggle
}

case "$1" in
case "${1}" in
--toggle)
toggle
;;
Expand Down

0 comments on commit 8798346

Please sign in to comment.