-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbtconnect.sh
More file actions
executable file
·36 lines (30 loc) · 913 Bytes
/
btconnect.sh
File metadata and controls
executable file
·36 lines (30 loc) · 913 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/bash
# Here we set the Bluetooth device address
device_address="50:C2:ED:B9:39:7E"
# Get the connection status of the device
connection_status=$(bluetoothctl info $device_address | grep "Connected:" | awk '{print $2}')
# Here we determine status based on connection status
if [ "$connection_status" == "yes" ]; then
status="connected"
else
status="disconnected"
fi
# Let's print initial status
echo "Device $device_address is currently $status"
# If the device is connected, disconnect it
if [ "$connection_status" == "yes" ]; then
echo "Disconnecting from $device_address..."
status="disconnected"
bluetoothctl << EOF
disconnect $device_address
EOF
else
# If the device is disconnected, connect to it
echo "Connecting to $device_address..."
status="connected"
bluetoothctl << EOF
connect $device_address
EOF
fi
# Print final status
echo "Device $device_address is now $status"