Skip to content

Instantly share code, notes, and snippets.

@gingerbeardman
Last active October 23, 2023 23:37
Show Gist options
  • Save gingerbeardman/05030c73714b3aa3202aeee7f21c3b1e to your computer and use it in GitHub Desktop.
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)
#!/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
@gingerbeardman
Copy link
Author

gingerbeardman commented Sep 22, 2023

The pin is each pair of the MAC address in reverse. But the resulting information is not human readable and cannot be typed using a keyboard because it's out of the range of the alphabet. Which is why it's managed here by a script.

It's a shame Nintendo picked such a pin. And it's a shame macOS has removed most support for Nintendo controllers.

@Noah40
Copy link

Noah40 commented Oct 23, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment