aboutsummaryrefslogtreecommitdiff
path: root/users/ryan/modules/sketchybar/bar-config/plugins/brightness.sh
diff options
context:
space:
mode:
Diffstat (limited to 'users/ryan/modules/sketchybar/bar-config/plugins/brightness.sh')
-rwxr-xr-xusers/ryan/modules/sketchybar/bar-config/plugins/brightness.sh29
1 files changed, 29 insertions, 0 deletions
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 @@
1#!/usr/bin/env bash
2# backlight -> brightness. Requires the `brightness` CLI (brew install brightness).
3# NOTE: reading/writing internal-display brightness is unreliable on Apple Silicon;
4# the item hides itself if the tool or a readable value is unavailable.
5source "$CONFIG_DIR/colors.sh"
6source "$CONFIG_DIR/icons.sh"
7
8command -v brightness >/dev/null 2>&1 || { sketchybar --set "$NAME" drawing=off; exit 0; }
9
10read_val() { brightness -l 2>/dev/null | awk '/display 0: brightness/{print $NF}'; }
11
12if [ "$SENDER" = "mouse.scrolled" ] && command -v bc >/dev/null 2>&1; then
13 CUR="$(read_val)"
14 if [ -n "$CUR" ]; then
15 case "$INFO" in
16 -*) brightness "$(echo "$CUR - 0.05" | bc)" 2>/dev/null ;; # scroll down
17 *) brightness "$(echo "$CUR + 0.05" | bc)" 2>/dev/null ;; # scroll up
18 esac
19 fi
20fi
21
22CUR="$(read_val)"
23[ -z "$CUR" ] && { sketchybar --set "$NAME" drawing=off; exit 0; }
24PCT="$(printf '%.0f' "$(echo "$CUR * 100" | bc -l 2>/dev/null)" 2>/dev/null)"
25[ -z "$PCT" ] && PCT=0
26
27if [ "$PCT" -ge 50 ]; then ICON=$BL_HIGH; else ICON=$BL_LOW; fi
28# Waybar: {percent}% {icon}
29sketchybar --set "$NAME" drawing=on label="${PCT}% ${ICON}"