blob: 87a245f78801045992736b53e9bd973ec1cf74c6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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}"
|