scripts/btconnect.sh
2025-03-26 21:37:21 +01:00

31 lines
730 B
Bash
Executable File

#!/bin/bash
# Configuration
DEVICE_MAC_ADDRESS="88:C9:E8:F4:4A:FF" # Replace with your device's MAC address
# Function to check if a device is connected
is_device_connected() {
bluetoothctl info "$DEVICE_MAC_ADDRESS" | grep -q "Connected: yes"
}
# Function to connect the device
connect_device() {
echo -e "connect $DEVICE_MAC_ADDRESS\nquit" | bluetoothctl
}
# Function to disconnect the device
disconnect_device() {
echo -e "disconnect $DEVICE_MAC_ADDRESS\nquit" | bluetoothctl
}
# Main logic
if is_device_connected; then
echo "Device $DEVICE_MAC_ADDRESS is already connected. Disconnecting..."
disconnect_device
else
echo "Device $DEVICE_MAC_ADDRESS is not connected. Connecting..."
connect_device
fi
exit 0