Bluetooth reconnect script

I own a pair of BOSE QuietComfort 35 bluetooth headphones, which I use with both my laptop and my phone.

This works great with Linux (not at all on Windows) but sometimes it takes a bit long for it to reconnect if I have moved out of reach for the laptop. (E.g. going for a cup of coffee).

There are ways to force it to reconnect faster, using the bluetooth tray icon, but it involves clicking.

So, i made this little script, that can be launched from a hotkey, making the headset and laptop reconnect immediately

#!/usr/bin/bash
(
  usleep 10000
  echo 'connect 04:52:C7:00:00:00'
  usleep 1000000
  echo quit
  usleep 10000
) | bluetoothctl

Remember to replace the mac address with the mac address of your device. You can obtain this by running bluetoothctl, and then enter the devices command. This will list all your paired devices and their mac addresses.