Skip to content

Instantly share code, notes, and snippets.

@JuanMiguelGM
Last active October 28, 2021 15:01
Show Gist options
  • Save JuanMiguelGM/3cb67bc6b8c92cbc0b3c6522d3cd5add to your computer and use it in GitHub Desktop.
Save JuanMiguelGM/3cb67bc6b8c92cbc0b3c6522d3cd5add to your computer and use it in GitHub Desktop.
# install this as pre-requisite
brew install bluetoothconnector
brew install switchaudio-osx
# In automator, create a new "Quick Action" Shell Script with no input and in any application:
# mac and name for the airpods can be found executing: BluetoothConnector
set -e
mac=0c-3b-50-96-75-34
name="AirPods Pro de Juan Miguel"
mic_name="Yeti Nano"
/usr/local/bin/BluetoothConnector --connect "${mac}" 1>&2
while [ `/usr/local/bin/BluetoothConnector --status "${mac}"` != Connected ]
do
sleep 1
done
until /usr/local/bin/SwitchAudioSource -a | grep "${name}"
do
sleep 1
done
/usr/local/bin/SwitchAudioSource -s "${name}" 1>&2
/usr/local/bin/SwitchAudioSource -s "${mic_name}" -t input 1>&2
until /usr/local/bin/SwitchAudioSource -c | grep "${name}"
do
sleep 1
done
until /usr/local/bin/SwitchAudioSource -c -t input | grep "${mic_name}"
do
sleep 1
done
# Sound
/usr/bin/say "Connected."
# or notification
/usr/bin/osascript -e 'display notification "Connected!" with title "Yeti"'
# in System Preferences -> Keyboard -> Services -> Scroll to the bottom, you'll see the new quick action and can define a shortcut
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment