Skip to content

Instantly share code, notes, and snippets.

@e-minguez
Created September 23, 2025 13:10
Show Gist options
  • Save e-minguez/8b61afd87cc5a83e61d69793f469098b to your computer and use it in GitHub Desktop.
Save e-minguez/8b61afd87cc5a83e61d69793f469098b to your computer and use it in GitHub Desktop.
kbbrightness on omarchy with macbook
# #!/usr/bin/env bash
# Based on
# https://wiki.archlinux.org/title/Hyprland#Keyboard_backlight_notifications
# Save it as ~/.config/hypr/scripts/kbbacklight
# Then used the following bindings
# bindeld = , code:238, Keyboard brightness up, exec, ~/.config/hypr/scripts/kbbacklight --inc
# bindeld = , code:237, Keyboard brightness down, exec, ~/.config/hypr/scripts/kbbacklight --dec
iDIR="$HOME/.config/mako/icons"
# Get brightness
get_backlight() {
LIGHT="$(cat /sys/class/leds/*::kbd_backlight/brightness)"
echo "${LIGHT}"
}
# Get icons
get_icon() {
export current=$(( ($(cat /sys/class/leds/*::kbd_backlight/brightness) * 100) / 255 ))
if [[ ("$current" -ge "0") && ("$current" -le "20") ]]; then
export icon="$iDIR/brightness-20.png"
elif [[ ("$current" -ge "20") && ("$current" -le "60") ]]; then
export icon="$iDIR/brightness-60.png"
elif [[ ("$current" -ge "60") && ("$current" -le "100") ]]; then
export icon="$iDIR/brightness-100.png"
fi
}
# Notify
notify_user() {
#notify-send -h string:x-canonical-private-synchronous:sys-notify -u low -i "$icon" "Keyboard Brightness : $(brightnessctl -d '*::kbd_backlight' g)"
notify-send -h string:x-canonical-private-synchronous:sys-notify -u low -i "$icon" "$current"
}
# Increase brightness
inc_backlight() {
brightnessctl -q -d *::kbd_backlight set 10%+ && get_icon && notify_user
}
# Decrease brightness
dec_backlight() {
brightnessctl -q -d *::kbd_backlight set 10%- && get_icon && notify_user
}
# Zero brightness
zero_backlight() {
brightnessctl -q -d *::kbd_backlight s 0%
}
# Full brightness
full_backlight() {
brightnessctl -q -d *::kbd_backlight s 100%
}
# Execute accordingly
if [[ "$1" == "--get" ]]; then
brightnessctl -q -d '*::kbd_backlight' g
elif [[ "$1" == "--inc" ]]; then
inc_backlight
elif [[ "$1" == "--dec" ]]; then
dec_backlight
elif [[ "$1" == "--zero" ]]; then
zero_backlight
elif [[ "$1" == "--full" ]]; then
full_backlight
else
get_backlight
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment