Skip to content

Instantly share code, notes, and snippets.

@anoother
Created April 5, 2018 20:20
Show Gist options
  • Save anoother/a1df15482448584c95dc7da504a80eec to your computer and use it in GitHub Desktop.
Save anoother/a1df15482448584c95dc7da504a80eec to your computer and use it in GitHub Desktop.
#!/bin/bash
### Pair a Logitech MX Anywhere 2 mouse with a Linux host. It shouldn't be this complicated.
### Credits go to James Anthony here: http://askubuntu.com/questions/741330/how-do-i-get-logitech-mx-anywhere-2-to-work-in-16-04-bluetooth-smart
DEVICE_REGEX='MX Anywhere 2'
echo 'Please put your device into pairing mode if it is not already.'
echo -n 'Waiting for device detection'
while true; do
echo -n '.'
sleep 1
found=$(echo -e '\npower off\npower on\nscan on' | \
bluetoothctl 2>/dev/null | grep -E "${DEVICE_REGEX}") && break
done
found=$(echo $found | grep -oE '([0-9A-Z]{2}:){5}[0-9A-Z]{2}' | sort | uniq)
while read -r device; do
bluetoothctl 2>/dev/null <<EOF
power off
power on
connect $device
trust $device
connect $device
pair $device
unblock $device
power off
power on
EOF
done <<< "$found"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment