Skip to content

Instantly share code, notes, and snippets.

@zoe1337
Created April 3, 2020 20:19
Show Gist options
  • Save zoe1337/6053e7afa559a84815e62e0e0c52169c to your computer and use it in GitHub Desktop.
Save zoe1337/6053e7afa559a84815e62e0e0c52169c to your computer and use it in GitHub Desktop.
toggle mute of microphone using pulseaudio
#!/usr/bin/env bash
CARD_IDX="10" # use `pacmd list-sources` to find out which one
STATUS_FILE="$XDG_RUNTIME_DIR/micmute_status" # temp file to store state
INDICATOR_LED="2" # 0: num, 1: caps, 2: scroll lock
LED_WHEN_MUTED="on"
LED_WHEN_UNMUTED="off"
touch "$STATUS_FILE" # make sure it exist
mute() {
echo muting. # for debug
pacmd set-source-mute $CARD_IDX 1
xset -led $INDICATOR_LED led $LED_WHEN_MUTED
echo 1 > "$STATUS_FILE"
}
unmute() {
echo unmuting.
pacmd set-source-mute $CARD_IDX 0
xset -led $INDICATOR_LED led $LED_WHEN_UNMUTED
echo 0 > "$STATUS_FILE"
}
toggle() {
pactl set-source-mute $CARD_IDX toggle
}
is_muted() {
return $(cat "$STATUS_FILE")
}
if [ "$(cat $STATUS_FILE)" -eq 1 ]
then
unmute
else
mute
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment