Created
April 4, 2020 01:20
-
-
Save zoe1337/0da060c940c65f14638049bbd790f424 to your computer and use it in GitHub Desktop.
A more advanced form of mute-unmute, with true PTT functionality
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
## usage: after installation, microphone is unmuted only while you | |
## press the key specified here. shift+hotkey will lock the microphone state | |
## note that this only works consistently as long as you use this | |
## script and/or keybindings; it won't update state if you use pavucontrol | |
## or other method to mute/unmute. | |
## | |
## installation: ideally, just run this script from a terminal with the install parameter. | |
## if that fails for whatever reason, refer to | |
## https://www.reddit.com/r/linux_gaming/comments/7uaki4/psa_control_mute_push_to_talk_or_whatever_on/ | |
## as a starting point | |
## | |
## Also see https://wiki.archlinux.org/index.php/Xbindkeys for more info on xbindkeys | |
HOTKEY="XF86HomePage" # use `xbindkeys --multikey` to find what key you want to bind to | |
CARD_IDX="@DEFAULT_SOURCE@" | |
# if the default is not the one you try to control, use `pacmd list-sources` to find out the index | |
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="off" | |
LED_WHEN_UNMUTED="on" | |
mute() { | |
echo muting. | |
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 | |
} | |
toggle() { | |
touch "$STATUS_FILE" | |
if [ "$(cat $STATUS_FILE)" -eq 1 ] | |
then | |
unmute | |
else | |
mute | |
fi | |
} | |
if [ "$1" = "mute" ] | |
then | |
mute | |
exit 0 | |
fi | |
if [ "$1" = "unmute" ] | |
then | |
unmute | |
exit 0 | |
fi | |
if [ "$1" = "toggle" ] | |
then | |
toggle | |
exit 0 | |
fi | |
if [ "$1" = "install" ] | |
then | |
XBKRC="$HOME/.xbindkeysrc" | |
if [ "$2" != "" ] | |
then | |
HOTKEY="$2" | |
fi | |
if [ "$(grep PTT $XBKRC | wc -l)" -gt 0 ] | |
then | |
echo Ooops! Looks like there is already a PTT functionality in your .xbindkeysrc | |
echo This script isn\'t smart enough to deal with such situations. | |
echo | |
echo Please edit $XBKRC manually. | |
exit 1 | |
fi | |
echo Installing into $XBKRC, using $HOTKEY as hotkey | |
cat >> "$XBKRC" <<EOF | |
# unmute mic (PTT) | |
"$0 unmute" | |
Mod2 + $HOTKEY | |
# mute mic (PTT) | |
"$0 mute" | |
Mod2 + $HOTKEY + Release | |
# toggle mic mute | |
"$0 toggle" | |
Shift+Mod2 + $HOTKEY | |
EOF | |
chmod +x "$0" | |
echo "Make sure to run xbindkeys when you start your X session (xprofile or xinitrc)" | |
xbindkeys --poll-rc | |
exit 0 | |
fi | |
echo "Usage: $0 <mute|unmute|toggle|install>" | |
echo "Got: \"$*\"" | |
exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment