From 447698b826862186a151febe4dec22699fe54db4 Mon Sep 17 00:00:00 2001 From: MorganGeek Date: Sun, 19 Jul 2020 15:41:26 +0200 Subject: [PATCH] feature: manage macos sound devices - installed switchaudio-osx for managing macos sound devices e.g : muting a device or switching to a device - aliases/functions to switch/mute devices - always mute speakers and switch to headset before running a zoom session - new aliases for starting timeboxed zoom meetings --- Brewfile | 1 + dot_aliases/macos.sh | 10 +++++++++- dot_zsh_functions | 32 ++++++++++++++++++++++++++++++++ requirements.txt | 32 ++++++++++++++++++-------------- 4 files changed, 60 insertions(+), 15 deletions(-) diff --git a/Brewfile b/Brewfile index b46c40d..d0e25df 100644 --- a/Brewfile +++ b/Brewfile @@ -199,3 +199,4 @@ brew "fd" brew "git-delta" brew "sn0int" brew "prettier" +brew "switchaudio-osx" diff --git a/dot_aliases/macos.sh b/dot_aliases/macos.sh index 0ac8a14..e3c42b1 100755 --- a/dot_aliases/macos.sh +++ b/dot_aliases/macos.sh @@ -19,5 +19,13 @@ alias emptytrash="sudo rm -rfv /Volumes/*/.Trashes; sudo rm -rfv $HOME/.Trash; s # via https://github.com/richinfante/dotfiles/blob/0e1df2d833257e3a3ca2e4fcc8f2f128d52b5d29/dotfiles/.profile_setup/30-aliases.sh alias finder="open ." alias cls="clear; printf '\e[3J'" -alias zoom="open -na 'zoom.us'" +# Sound management +alias mute_headset='mute_device "Plantronics BT600"' +alias mute_speakers='mute_device "Haut-parleurs MacBook Pro"' +alias switch_headset='mute_speakers && switch_device "Plantronics BT600"' +alias switch_speakers='mute_headset && switch_device "Haut-parleurs MacBook Pro"' +# Meeting management +alias zoom="switch_headset && open -na 'zoom.us'" alias nozoom="pkill 'zoom.us'" +alias zoom30='zoomtimeboxed 30' +alias zoom60='zoomtimeboxed 60' diff --git a/dot_zsh_functions b/dot_zsh_functions index 2d4e492..a48f7df 100644 --- a/dot_zsh_functions +++ b/dot_zsh_functions @@ -174,6 +174,38 @@ function suggest_aliases() { done < <(top_commands_full "" "$search_input_size" | awk '{ $1=""; $2=""; $3=""; print}' | awk 'NF' | awk '{$1=$1};1' | awk -v COUNT=1 'NF>COUNT' H "-$search_input_size") } +# Sound management +# Inspired by https://apple.stackexchange.com/a/213048/231885 for switching devices +# and https://coderwall.com/p/22p0ja/set-get-osx-volume-mute-from-the-command-line for volume management +function mute_device() { + local current_device=$(SwitchAudioSource -c) + local target_device="$1" + if SwitchAudioSource -a | grep "$target_device" 1>/dev/null; then + SwitchAudioSource -s "$1" 1>/dev/null + osascript -e 'set volume output muted true' + success "device $target_device muted" + SwitchAudioSource -s "$current_device" 1>/dev/null + if [ "$current_device" != "$target_device" ]; then + arrow "switching back to $current_device" + fi + arrow "currently using $target_device" + else + error "sound device not found : $target_device (maybe it's disconnected ?)" + fi +} +function switch_device() { + local target_device="$1" + if SwitchAudioSource -a | grep "$target_device" 1>/dev/null; then + if SwitchAudioSource -s "$1" 1>/dev/null; then + success "switched to $target_device" + else + error "failed to switch to $target_device" + fi + else + error "sound device not found : $target_device (maybe it's disconnected ?)" + fi +} + # Web Crawling function aboutpage() { year=$(echo "$*" | egrep --extended-regexp --only-matching '\b[[:digit:]]{4}\b' H -n1) diff --git a/requirements.txt b/requirements.txt index d5f91d1..81eaa3c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,15 +9,18 @@ attrs==19.3.0 Automat==0.8.0 autopep8==1.4.4 backcall==0.1.0 -beautifulsoup4==4.8.1 +beautifulsoup4==4.9.1 beautysh==6.0.1 black==19.10b0 bleach==3.1.4 bs4==0.0.1 cachetools==3.1.1 -certifi==2019.9.11 +castero==0.8.0 +certifi==2020.6.20 cffi==1.13.2 chardet==3.0.4 +CJKwrap==2.2 +click==7.1.2 colorama==0.4.1 colorzero==1.1 configobj==5.0.6 @@ -33,19 +36,19 @@ flake8==3.7.9 future==0.18.2 gitlint==0.13.1 google-api-python-client==1.7.11 -google-auth==1.7.0 google-auth-httplib2==0.0.3 +google-auth==1.7.0 gpg==1.13.1 gpiozero==1.5.1 guizero==1.1.0 haxor-news==0.4.3 httplib2==0.18.0 hyperlink==19.0.0 -idna==2.8 +idna==2.10 incremental==17.5.0 ipykernel==5.1.3 -ipython==7.9.0 ipython-genutils==0.2.0 +ipython==7.9.0 isort==4.3.21 jedi==0.15.1 jmespath==0.9.4 @@ -75,11 +78,12 @@ pipenv==2018.11.26 pkginfo==1.5.0.1 pocket==0.3.6 prompt-toolkit==2.0.10 +proselint==0.10.2 Protego==0.1.15 psutil==5.7.0 ptyprocess==0.6.0 -pyasn1==0.4.7 pyasn1-modules==0.2.7 +pyasn1==0.4.7 pycodestyle==2.5.0 pycparser==2.19 PyDispatcher==2.0.5 @@ -92,13 +96,15 @@ pyhcl==0.4.0 pylint==2.4.3 pyOpenSSL==19.0.0 pyparsing==2.4.4 -PyQt5==5.13.2 PyQt5-sip==12.7.0 +PyQt5==5.13.2 PyQtChart==5.13.1 pyserial==3.4 PySocks==1.7.1 python-dateutil==2.8.0 python-jenkins==1.5.0 +python-mpv==0.4.8 +python-vlc==3.0.10114 pytz==2019.3 PyYAML==5.1.2 pyzmq==18.1.0 @@ -110,17 +116,18 @@ readme-renderer==24.0 rebound-cli==2.0.0 regex==2019.11.1 relint==1.2.1 -requests==2.22.0 requests-futures==1.0.0 requests-toolbelt==0.9.1 +requests==2.24.0 rsa==3.4.2 rtv==1.27.0 Scrapy==1.8.0 semver==2.9.0 service-identity==18.1.0 sh==1.12.14 +six==1.15.0 slacker==0.13.0 -soupsieve==1.9.5 +soupsieve==2.0.1 stashy==0.6 stem==1.7.1 toml==0.10.0 @@ -133,11 +140,11 @@ Twisted==19.7.0 twitter==1.18.0 typed-ast==1.4.0 uritemplate==3.0.0 -urllib3==1.25.6 +urllib3==1.25.9 urwid==2.0.1 vim-vint==0.3.21 -virtualenv==16.7.7 virtualenv-clone==0.5.3 +virtualenv==16.7.7 w3lib==1.21.0 wcwidth==0.1.7 webencodings==0.5.1 @@ -145,6 +152,3 @@ websocket-client==0.56.0 wrapt==1.11.2 yamllint==1.23.0 zope.interface==4.6.0 -click==7.1.2 -proselint==0.10.2 -six==1.15.0