-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathliskin-bluetooth-disconnect
More file actions
executable file
·38 lines (30 loc) · 909 Bytes
/
liskin-bluetooth-disconnect
File metadata and controls
executable file
·38 lines (30 loc) · 909 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
37
38
#!/usr/bin/env bash
# workaround for the bluetooth adapter blocking s2idle when devices are connected
# https://bugzilla.kernel.org/show_bug.cgi?id=215768
set -eu -o pipefail
function o { printf -->&2 "%s:%s\\n" "${0##*/}" "$(printf " %q" "$@")"; "$@"; }
function with-devices {
local dev
{ busctl tree --list org.bluez || :; } | while read -r dev; do
if [[ $dev == /org/bluez/*/dev_??_??_??_??_??_?? ]]; then
"$1" "$dev" "${@:2}"
fi
done
}
function if-connected {
local dev; dev=${1:?}; shift
local connected
connected=$(busctl get-property -j org.bluez "$dev" org.bluez.Device1 Connected | jq -r .data) || connected=false
if [[ $connected == true ]]; then
"$1" "$dev" "${@:2}"
fi
}
function disconnect {
o busctl call org.bluez "${1:?}" org.bluez.Device1 Disconnect || :
}
function disconnect-all {
with-devices if-connected disconnect
}
case "$1" in
pre) disconnect-all ;;
esac