From d2b62c9d6f30a0ea88b2a235cde120cd10ba332b Mon Sep 17 00:00:00 2001 From: Ryan Schanzenbacher Date: Sat, 11 Jul 2026 22:14:43 -0400 Subject: Sketchybar now, got tired of the battery issue --- .../sketchybar/bar-config/plugins/brightness.sh | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100755 users/ryan/modules/sketchybar/bar-config/plugins/brightness.sh (limited to 'users/ryan/modules/sketchybar/bar-config/plugins/brightness.sh') diff --git a/users/ryan/modules/sketchybar/bar-config/plugins/brightness.sh b/users/ryan/modules/sketchybar/bar-config/plugins/brightness.sh new file mode 100755 index 0000000..87a245f --- /dev/null +++ b/users/ryan/modules/sketchybar/bar-config/plugins/brightness.sh @@ -0,0 +1,29 @@ +#!/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}" -- cgit v1.3