How to use an iMac’s bluetooth keyboard and mouse after wiping out MacOS and setting up Ubuntu.
make sure the keyboard is turned off (e.g. remove batteries)
enter the `bluetoothctl` shell
sudo bluetoothctl
power on bluetooth and scan for devices
bluetoothctl> power on
bluetoothctl> scan on
turn the keyboard on and keep its power button pressed
Wait for the keyboard to appear in scanned devices, and copy its MACADDRESS
issue the following commands
bluetoothctl> trust MACADDRESS
bluetoothctl> pair MACADDRESS
wait for a PIN to appear
release the keyboard’s power button and enter the PIN on the keyboard and press ENTER
The keyboard should now be paired and will automatically pair the next time the system is turned on.
Pairing the mouse uses similar steps.