Last active
October 23, 2023 23:37
-
-
Save gingerbeardman/05030c73714b3aa3202aeee7f21c3b1e to your computer and use it in GitHub Desktop.
Automatically pair a Wii Remote to macOS using blueutil command-line tool (Intel-only? fails on Apple silicon)
This file contains 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
#!/usr/bin/env bash | |
# requirements: blueutil | |
echo "Hold both 1+2 buttons on Wii Remote and wait for 30 seconds" | |
# get MAC Address of Wii Remote | |
MAC=`$(which blueutil) --inquiry 5 2>&1 | grep 'address' | awk '{print substr($2,1,17)}'` | |
(killall -m 'blueutil*' 2>&1) >/dev/null | |
echo "MAC: $MAC" | |
# prepare HEX | |
HEX=`echo $MAC | tr -d '-'` | |
# PIN is MAC Address HEX pairs in reverse order | |
PIN="\x${HEX:10:2}\x${HEX:8:2}\x${HEX:6:2}\x${HEX:4:2}\x${HEX:2:2}\x${HEX:0:2}" | |
# try to PAIR with PIN | |
echo "ATTEMPTING PAIR" | |
echo "$PIN" | $(which blueutil) --pair $MAC >/dev/null 2>&1 | |
# fail? | |
if [ $? -ne 0 ]; then | |
echo "PAIR FAILED" | |
else | |
# now we can CONNECT | |
echo "ATTEMPTING CONNECT" | |
$(which blueutil) --connect $MAC >/dev/null 2>&1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I by no means know shell script well but i tried to hardcode in the MAC address here because blueutil was acting weirdly. Anyways I get the error Failed to pair "d8-6b-f7-db-a2-5e" with error 0x1f (Unspecified Error)
Here is the code:
#!/usr/bin/env bash
MAC="d8-6b-f7-db-a2-5e"
(killall -m 'blueutil*' 2>&1) >/dev/null
echo "MAC: $MAC
PIN="\xe5\x2a\xbd\x7f\xb6\x8d"
echo "ATTEMPTING PAIR"
echo -n -e "$PIN" | $(which blueutil) --pair $MAC
if [ $? -ne 0 ]; then
echo "PAIR FAILED"
else
echo "ATTEMPTING CONNECT"
$(which blueutil) --connect $MAC
fi