commit 02fc802399ab42d55a1d7f3772322ca97ead7c7f Author: Graham Helton Date: Sat Oct 30 17:05:58 2021 -0400 first commit diff --git a/README.MD b/README.MD new file mode 100644 index 0000000..4a30bea --- /dev/null +++ b/README.MD @@ -0,0 +1,32 @@ +# Bluetoother +## Usage +1. Install the bluetooth software +```bash +sudo apt-get -y install bluetooth bluez bluez-tools rfkill +``` + +2. Find out your device's hardware MAC Address +```bash +bluetoothctl +scan on + +scan off +exit +``` +2. Edit the script and input your hardware's MAC address + +3. Run the script +```bash +git clone https://github.com/grahamhelton/bluetoother +chmod +x bluetoother +./bluetoother + +-> Bluetooth service enabled, trying to connect you... +-> You're connected! +``` + +## Running with keypress in I3 +bindsym #Mod+shift+b exec /path/to/bluetoother + +## References +https://computingforgeeks.com/connect-to-bluetooth-device-from-linux-terminal/ diff --git a/bluetoother b/bluetoother new file mode 100755 index 0000000..cbffec7 --- /dev/null +++ b/bluetoother @@ -0,0 +1,28 @@ +#! /bin/bash +mac="INSERT YOUR MAC ADDRESS HERE" +active=$(systemctl is-active bluetooth.service) +if [[ "$active" == "active" ]]; then + echo "Bluetooth service enabled, trying to connect you..." +else + echo "Bluetooth is not enabled. Running systemctl start bluetooth.service" + systemctl start bluetooth.service +fi + +#unblock bluetooth +rfkill unblock bluetooth +# Use bluetoothctl utility to make the connection. +bluetoothctl remove $mac 1>/dev/null +bluetoothctl agent KeyboardOnly 1>/dev/null +bluetoothctl default-agent 1>/dev/null +bluetoothctl power on 1>/dev/null + +# if your mac address is found, connect to it +if bluetoothctl scan on | grep -q "$mac"; then + bluetoothctl pair $mac 1>/dev/null + bluetoothctl trust $mac 1>/dev/null + if bluetoothctl connect $mac | grep -q "Connection successful"; then + echo "You're connected!" + exit 0 + fi +fi +echo "Could not connect"