#!/usr/bin/env bash # backlight -> brightness. Requires the `brightness` CLI (brew install brightness). # NOTE: reading/writing internal-display brightness is unreliable on Apple Silicon; # the item hides itself if the tool or a readable value is unavailable. source "$CONFIG_DIR/colors.sh" source "$CONFIG_DIR/icons.sh" command -v brightness >/dev/null 2>&1 || { sketchybar --set "$NAME" drawing=off; exit 0; } read_val() { brightness -l 2>/dev/null | awk '/display 0: brightness/{print $NF}'; } if [ "$SENDER" = "mouse.scrolled" ] && command -v bc >/dev/null 2>&1; then CUR="$(read_val)" if [ -n "$CUR" ]; then case "$INFO" in -*) brightness "$(echo "$CUR - 0.05" | bc)" 2>/dev/null ;; # scroll down *) brightness "$(echo "$CUR + 0.05" | bc)" 2>/dev/null ;; # scroll up esac fi fi CUR="$(read_val)" [ -z "$CUR" ] && { sketchybar --set "$NAME" drawing=off; exit 0; } PCT="$(printf '%.0f' "$(echo "$CUR * 100" | bc -l 2>/dev/null)" 2>/dev/null)" [ -z "$PCT" ] && PCT=0 if [ "$PCT" -ge 50 ]; then ICON=$BL_HIGH; else ICON=$BL_LOW; fi # Waybar: {percent}% {icon} sketchybar --set "$NAME" drawing=on label="${PCT}% ${ICON}"