#!/usr/bin/env bash source "$CONFIG_DIR/colors.sh" source "$CONFIG_DIR/icons.sh" CACHE="/tmp/sketchybar_${NAME}.txt" case "$SENDER" in mouse.entered) [ -f "$CACHE" ] && sketchybar --set "$NAME.details" label="$(cat "$CACHE")" sketchybar --set "$NAME" popup.drawing=on; exit 0 ;; mouse.exited) sketchybar --set "$NAME" popup.drawing=off; exit 0 ;; esac if ! command -v blueutil >/dev/null 2>&1; then sketchybar --set "$NAME" label="$BT_OFF" label.color=$TEXT_DIM printf '%s' "blueutil not installed" > "$CACHE" exit 0 fi if [ "$1" = "toggle" ]; then if [ "$(blueutil -p)" = "1" ]; then blueutil -p 0; else blueutil -p 1; fi fi if [ "$(blueutil -p)" = "1" ]; then NAMES="$(blueutil --connected 2>/dev/null | grep -o 'name: "[^"]*"' | sed 's/name: "//; s/"$//' | paste -sd , - | sed 's/,/, /g')" COUNT="$(blueutil --connected 2>/dev/null | grep -c 'name:')" if [ "$COUNT" -gt 0 ]; then sketchybar --set "$NAME" label="$BT_CONNECTED" label.color=$TEXT printf '%s' "Bluetooth on · $COUNT connected: $NAMES" > "$CACHE" else sketchybar --set "$NAME" label="$BT_ON" label.color=$TEXT printf '%s' "Bluetooth on · no devices connected" > "$CACHE" fi else sketchybar --set "$NAME" label="$BT_OFF" label.color=$TEXT_DIM printf '%s' "Bluetooth off" > "$CACHE" fi