From d3c842947f1ca879ada44deb688e6a17ae5be06a Mon Sep 17 00:00:00 2001 From: TheK4n Date: Sun, 9 Apr 2023 00:24:08 +0300 Subject: [PATCH] fix(i3status): change hardcoded device uuid to dynamic searching connected device with battery percentage --- home/user/.local/bin/i3status_wrapper | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/home/user/.local/bin/i3status_wrapper b/home/user/.local/bin/i3status_wrapper index 1d6c796..cbde841 100755 --- a/home/user/.local/bin/i3status_wrapper +++ b/home/user/.local/bin/i3status_wrapper @@ -38,13 +38,17 @@ function remove_holder { } function headphones { + for uuid in $(bluetoothctl devices | cut -f2 -d' ') + do + local device_info="$(bluetoothctl info "$uuid")" - battery_status="$(bluetoothctl info 14:0A:29:0A:6A:2F | grep "Battery Percentage" | awk -F '[()]' '{ print "🎧🔋"$2"%" }')" - - local json="{ \"full_text\": \"$battery_status\", \"color\": \"#FFFFFF\"}" - - json_array=$(update_holder holder__headphones "$json") - + if [ -n "$(echo $device_info | grep 'Connected: yes\|Battery Percentage')" ]; then + battery_status="$(echo "$device_info" | grep 'Battery Percentage' | awk -F '[()]' '{ print "🎧🔋"$2"%" }')" + local json="{ \"full_text\": \"$battery_status\", \"color\": \"#FFFFFF\"}" + json_array=$(update_holder holder__headphones "$json") + break + fi + done } i3status | (read line; echo "$line"; read line ; echo "$line" ; read line ; echo "$line" ; while true