From 150d9a1de21066d350c811f7876fc27d3e6e0916 Mon Sep 17 00:00:00 2001 From: Andrew Date: Wed, 10 Jun 2020 15:58:51 +0400 Subject: Added some scripts --- .local/bin/scripts/bluecontrol | 61 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100755 .local/bin/scripts/bluecontrol (limited to '.local/bin/scripts/bluecontrol') 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 -- cgit v1.2.3