Inspired by bluetooth-autoconnect, but much simplier and actually works. Based on systemd service (daemon) which does the following, repeatedly:
- Run check command (e.g. check if device exists). If it returns zero, continue.
- Try to run
bluetoothctl connect <MAC>
. No checks if bluetooth is on, etc. Dead simple. - Sleep for
delay
seconds (configurable).
git clone https://gist.github.com/bc178789a441ce73b51e1e0637393aac.git bluetooth-reconnect && cd bluetooth-reconnect
sudo chmod +x bluetooth-reconnect
# Edit `bluetooth-reconnect` file according to your needs. Try if it works with ./bluetooth-reconnect
sudo cp bluetooth-reconnect /usr/bin
sudo cp bluetooth-reconnect.service /etc/systemd/system
sudo systemctl enable bluetooth-reconnect
sudo systemctl start bluetooth-reconnect
# Check if it's alive
sudo systemctl status bluetooth-reconnect
- How
test
command works: https://www.computerhope.com/unix/test.htm - How to loop with equal invervals: https://unix.stackexchange.com/a/214660