Created
November 4, 2022 07:04
-
-
Save MihailPreis/39d4314a459557e8fc1baa03d4b1c22f to your computer and use it in GitHub Desktop.
Script for unpair/pair selected bluetooth devices
This file contains hidden or 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
#!/bin/bash | |
# | |
# This script unpair selected device if is paired and vice versa | |
# for example, to quickly switch mouse and keyboard between macs | |
# Install `blueutil` with Brew before use this script! | |
# For get device ID run `blueutil --paired` and get "address" (as is) | |
# P.S. This script will be more convenient with Automator... | |
# for Homebrew on M1 | |
export PATH="$PATH:/opt/homebrew/bin" | |
if ! which blueutil &> /dev/null; then | |
>&2 echo "blueutil not installed. Run: brew install blueutil" | |
exit 1 | |
fi | |
_switch() { | |
if [[ "$(blueutil --is-connected $1)" = '1' ]]; then | |
blueutil --unpair $1 | |
else | |
blueutil --unpair $1 | |
sleep 0.2 | |
blueutil --pair $1 | |
sleep 0.2 | |
blueutil --connect $1 | |
fi | |
} | |
# Mike’s Magic Mouse | |
_switch "0c-e4-41-1c-07-a4" | |
# Mike’s Magic Keyboard | |
_switch "ac-49-db-f3-95-fc" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment