teams_micmute/micmute

92 lines
2.0 KiB
Plaintext
Raw Normal View History

2023-10-31 21:37:41 +11:00
#!/usr/bin/env bash
. ${HOME}/code/bashtools/bashtools.sh
if [[ -z $HAVE_BASHTOOLS ]]; then
echo "ERROR: bashtools not installed download from https://git.nethack.net/rob/bashtools" >/dev/stderr
exit 1
fi
doit=0
teamsapp="Microsoft Teams classic"
function usage() {
echo "usage: $0 [-y] [\"Microsoft Teams Application Title\"]"
echo
echo "Toggles ms teams mic mute on/off."
echo
echo "Unless -y is used, script will run in test mode and not"
echo "actually do anything."
}
function maxof() {
[[ -z $* ]] && return 1
echo "$*" | tr ' ' '\n' | egrep '^[0-9]+$' | sort -n | tail -1
}
function cleanup() {
echo -e -n "$PLAIN"
tput cnorm
echo
}
trap cleanup EXIT
if [[ $1 == *-h* ]]; then
usage
exit 1
fi
if [[ $1 == "-y" ]]; then
doit=1
shift
fi
if [[ -n $* ]]; then
teamsapp="$*"
fi
if [[ $doit -eq 1 ]]; then
read -p "Is the mic currently muted? " yn
[[ $yn == "y" ]] && mute=1 || mute=0
else
warn "Running in test mode. use -y to actually control mic."
mute=0
fi
csecho "$CYAN" "Space to toggle, anything else to quit"
txt=" "
col_recording="${ORANGE}${BOLD}"
col_muted="${GREY}"
txt_recording="🎤 RECORDING 🎤"
txt_muted="🔇 (muted) 🔇"
n=$(maxof ${#txt_recording} ${txt_muted})
n=$((n + 5))
tput civis
while [ 1 ]; do
if [[ $mute -eq 0 ]]; then
col="${col_recording}"
txt="${txt_recording}"
else
col="${col_muted}"
txt="${txt_muted}"
fi
echo -en '\r'
printf "[${col}%-${n}s$PLAIN]" "$txt"
read -s -N 1 -p "" dummy
[[ $dummy != " " ]] && exit 0
if [[ $doit -eq 1 ]]; then
# Send shift+command+m to teams (toggle mute)
#tell application "System Events"
# set prev to name of 1st process whose frontmost is true
#end tell
osascript << EOF
tell application "System Events"
tell application "${teamsapp}" to activate
keystroke "m" using {shift down, command down}
end tell
EOF
#tell application prev
# activate
#end tell
fi
mute=$((1 - $mute))
done
exit 1