-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbt_toggle
More file actions
executable file
·19 lines (14 loc) · 883 Bytes
/
bt_toggle
File metadata and controls
executable file
·19 lines (14 loc) · 883 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/usr/bin/env bash
# Toggles the connection state of a bluetooth device using the devices MAC Address.
# The device MUST already be paired and trusted.
# The device's MAC Address can either be read from an environment variable or put in the function's local variable
# You can find the MAC Address for your desired device by running `bluetoothctl paired-devices` and noting the relevant output.
bt_toggle() {
# Place the device's MAC Address here if you are using this script as a keyboard shortcut.
# This is required because the script runs in its own environment when executed as a keyboard shortcut.
local DEVICE_MAC_ADDR="88:C9:E8:DB:EA:78"
bluetoothctl info "$DEVICE_MAC_ADDR" | grep --quiet "Connected: no" \
&& bluetoothctl connect "$DEVICE_MAC_ADDR" &> /dev/null \
|| bluetoothctl disconnect "$DEVICE_MAC_ADDR" &> /dev/null
}
bt_toggle