From f4343686d3b26a78389d3f5a6e964a81e5c9e5c2 Mon Sep 17 00:00:00 2001 From: Rob Pearce Date: Tue, 31 Oct 2023 21:37:41 +1100 Subject: [PATCH] initial checkin --- README.md | 9 ++++++ micmute | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100755 README.md create mode 100755 micmute diff --git a/README.md b/README.md new file mode 100755 index 0000000..3577377 --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +# Overview + +Quick applescript-wrapped-in-bash script to toggle ms teams mute remotely via ssh. + +# Requirements + - [bash](https://www.gnu.org/software/bash/) + - [bashtools](https://git.nethack.net/rob/bashtools) + - MS Teams (obviously) + diff --git a/micmute b/micmute new file mode 100755 index 0000000..657774e --- /dev/null +++ b/micmute @@ -0,0 +1,91 @@ +#!/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