diff options
| author | Andrew <saintruler@gmail.com> | 2020-06-10 15:58:51 +0400 |
|---|---|---|
| committer | Andrew <saintruler@gmail.com> | 2020-06-10 15:58:51 +0400 |
| commit | 150d9a1de21066d350c811f7876fc27d3e6e0916 (patch) | |
| tree | 817af7b859245beb6f30d4972c2136f23e74e850 /.local/bin/scripts/bluecontrol | |
| parent | f5380f06e70e2118306b6f361143458edf292ac9 (diff) | |
Added some scripts
Diffstat (limited to '.local/bin/scripts/bluecontrol')
| -rwxr-xr-x | .local/bin/scripts/bluecontrol | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/.local/bin/scripts/bluecontrol b/.local/bin/scripts/bluecontrol new file mode 100755 index 0000000..ea36ff4 --- /dev/null +++ b/.local/bin/scripts/bluecontrol @@ -0,0 +1,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=3 + 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 "$devices" + 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 |