From 466cbbdcfd1f633f50ca9f025af72868c9233afa Mon Sep 17 00:00:00 2001 From: Alexander Bocken Date: Sat, 18 Apr 2020 21:26:30 +0200 Subject: [PATCH] Initial Project Version --- LICENSE | 21 +++++++++++++++++++ bthandler | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 LICENSE create mode 100755 bthandler diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..b9f7490 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 Alexander Bocken + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/bthandler b/bthandler new file mode 100755 index 0000000..4934d87 --- /dev/null +++ b/bthandler @@ -0,0 +1,63 @@ +#!/bin/zsh +#wait time to discover new devices in seconds +SCAN_PERIOD=5 +IDS=$(bluetoothctl paired-devices | awk '{print $2}') +echo $IDS > /tmp/bt_IDS +Devices=$(bluetoothctl paired-devices | awk '{for (i=3; i /tmp/bt_devices +actions="\nturn off\nturn on\nscan on\npair" +choice=$( echo $Devices$actions | dmenu -p 'BT:' ) +echo choice: $choice"test" + +cleanup(){ + rm -f /tmp/bt_devices + rm -f /tmp/bt_IDS + rm -f /tmp/paired_devices +} + + +case $choice in + "turn on") bluetoothctl power on + cleanup + exit;; + "turn off") bluetoothctl power off + cleanup + exit;; + "scan on") bluetoothctl power on && echo power on && sleep 2 + st -e bluetoothctl scan on + cleanup + exit;; + "pair") bluetoothctl power on + bluetoothctl scan on & disown + notify-send "Bluetooth" "Searching for devices, please wait a bit" + sleep $SCAN_PERIOD + all_devices=$(bluetoothctl devices | awk '{for (i=3; i /tmp/paired_devices + new_devices=$(echo $all_devices | grep -vf /tmp/paired_devices) + choice=$( echo $new_devices | dmenu -l 10 -p 'pair with which device?:' ) + if [ -n "$choice" ]; then + bluetoothctl devices | awk '{print $2}' > /tmp/bt_IDS + choice=$( echo $choice | sed 's/ $//') + dev_no=$(echo $all_devices | cat -n | grep "$choice" | awk '{print $1}') + echo device_no: $dev_no"neger" + dev_id=$(cat -n /tmp/bt_IDS | grep -E $dev_no"[[:space:]]" | awk '{print $2}' ) + echo dev_id: $dev_id"test" + bluetoothctl pair $dev_id && sleep 2 + bluetoothctl connect $dev_id + bluetoothctl scan off + fi + cleanup;; + +esac + +if [ -n "$choice" ]; then + choice=$( echo $choice | sed 's/ $//') + dev_no=$(cat -n /tmp/bt_devices | grep "$choice" | awk '{print $1}') + echo device_no: $dev_no + dev_id=$(cat -n /tmp/bt_IDS | grep $dev_no | awk '{print $2}') + echo dev_id: $dev_id"test" + bluetoothctl power on + bluetoothctl connect $dev_id +fi + +cleanup