#!/usr/bin/env bash # Collect connected devices bt_connected=$(bluetoothctl devices | while read -r line; do mac=$(echo "$line" | awk '{print $2}') if [ "$(bluetoothctl info "$mac" | awk '/Connected:/ {print $2}')" = "yes" ]; then echo "$line" | cut -d' ' -f3- fi done | sed '/^$/d') # remove empty lines # Determine icon if [ -n "$bt_connected" ]; then icon="" else icon="" fi # Escape for JSON bt_connected_json=$(printf '%s' "$bt_connected" | sed 's/"/\\"/g' | awk '{printf "%s\\n", $0}') # Output single JSON object echo "{\"text\": \"$icon\", \"tooltip\": \"$bt_connected_json\"}"