blob: f69def3030be96be45336bb5fa0d5f4928b98344 (
plain)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
#!/bin/sh
fGetDevices()
{
bluetoothctl -- devices
}
fGetDevice()
{
fGetDevices | dmenucmd
}
fPower()
{
local state=$(bluetoothctl -- show | grep -i "powered" | awk '{ print $2 }')
case $state in
yes) bluetoothctl -- power off && notify-send "Power turned off" ;;
no) bluetoothctl -- power on && notify-send "Power turned on" ;;
esac
}
fScan()
{
local time=5
notify-send "Turning on scanning for $time seconds"
timeout $time bluetoothctl -- scan on
notify-send "Scanning turned off"
}
fConnect()
{
local device=$(fGetDevices | dmenucmd | awk '{ print $2 }')
local output=$(bluetoothctl -- connect "$device")
(echo "$output" | grep -i "successful") && notify-send "Connection successful" && return
(echo "$output" | grep -i "failed") && notify-send "Failed to connect" && return
}
fRemove()
{
local device=$(fGetDevices | dmenucmd | awk '{ print $2 }')
bluetoothctl -- remove "$device"
notify-send "Removed device"
}
fDisconnect()
{
bluetoothctl -- disconnect
notify-send "Disconnected"
}
command=$(echo -e "connect\nremove\ndisconnect\nscan\npower" | dmenucmd)
case $command in
connect) fConnect ;;
remove) fRemove ;;
disconnect) fDisconnect ;;
scan) fScan ;;
power) fPower ;;
esac
# Update dwmblocks status if connected
pkill -RTMIN+9 dwmblocks
|