This script automates the reconnection of Bluetooth devices after switching operating systems in a dual-boot setup. Sometimes, previously saved devices do not reconnect automatically, requiring manual removal and reconnection. This script simplifies that process.
sudo pacman -S bluez bluez-utils
# OR
sudo apt-get install bluez bluez-utils
# OR use any other package manager compatible with your system
You have to give executable permission
chmod +x recoonectBluetooth
alternatively, you can use bash
keyword before script to execute it
bash reconncetBluetooth
You can move script to your scripts directory and export that path to bash, zsh, etc.
cd ~
mkdir scripts
cd scripts
git clone https://github.com/47seconds/reconnectBluetooth.git
mv reconnectBluetooth/reconnectBluetooth .
rm -rf reconnectBluetooth
vim ~/.bashrc
# add this at last line: export PATH=$HOME/scripts:$PATH
# :wq to save and exit vim
source ~/.bashrc
Now you can access this script from anywhere.
./reconnectBluetooth -h
# OR
./reconnectBluetooth --help
./reconnectBluetooth list
# OR
./reconnectBluetooth devices
./reconnectBluetooth [MAC ADDRESS DEVICE 1] [...]
./reconnectBluetooth -a [MAC ADDRESS DEVICE 1] [...]
# lists the saved devices in bluetooth
bluetoothctl devices
# to see MAC addresses of not saved devices, scan for them and note them somewhere
bluetooth
power on
scan on
./reconnectBluetooth
- Devices List Location: The list of devices is stored at
~/scripts/bluetoothDevices.txt
. - Append Command Caution: Never use the append (
-a
) command when the list is empty. Always initialize the list by adding devices first. - Script Caution: If not used carefully, the script may malfunction and attempt to connect to an empty list of devices, wasting time unnecessarily.
- Execution Ease: You don't need
./
if added script path to shell path