Created
September 5, 2025 07:09
-
-
Save thunder-coding/adc5a9cc6f467367d48ca41565b06750 to your computer and use it in GitHub Desktop.
Random keyboard color for ASUS TUF F15 on Linux (requires openrgb)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [Unit] | |
| Description=Random Color service | |
| [Service] | |
| Nice=19 | |
| CPUSchedulingPolicy=idle | |
| ExecStart=/root/random-color.sh | |
| [Install] | |
| WantedBy=multi-user.target |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/bash | |
| set -eou pipefail | |
| ### Configuration section | |
| # How much should each color shift by (maximum during each iteration) | |
| delta=5 | |
| brightness_file="/sys/devices/platform/asus-nb-wmi/leds/asus::kbd_backlight/brightness" | |
| maxbrightness_file="/sys/devices/platform/asus-nb-wmi/leds/asus::kbd_backlight/max_brightness" | |
| # How many iterations should we follow in the same direction. Helps stabilize the colors a bit instead of going stochastic | |
| iter=10 | |
| # Time (in seconds) between each update to the color | |
| interval=60 | |
| r=$((SRANDOM % 256)) | |
| g=$((SRANDOM % 256)) | |
| b=$((SRANDOM % 256)) | |
| dr=1 | |
| dg=1 | |
| db=1 | |
| i=0 | |
| while true; do | |
| if (( i <= 0 )); then | |
| dr=$((SRANDOM % 3 - 1)) | |
| dg=$((SRANDOM % 3 - 1)) | |
| db=$((SRANDOM % 3 - 1)) | |
| i=$iter | |
| fi | |
| r=$((r + dr * (SRANDOM % delta))) | |
| g=$((g + dg * (SRANDOM % delta))) | |
| b=$((b + db * (SRANDOM % delta))) | |
| # Increase the probability to choose brighter colors | |
| if ((r * r + g * g + b * b < 255*255)); then | |
| if (( r < 100 && SRANDOM % 2 == 0)); then | |
| r=$((r + delta)) | |
| fi | |
| if (( g < 100 && SRANDOM % 2 == 0)); then | |
| g=$((g + delta)) | |
| fi | |
| if (( b < 100 && SRANDOM % 2 == 0)); then | |
| b=$((b + delta)) | |
| fi | |
| fi | |
| if (( r > 255 )); then | |
| r=255 | |
| fi | |
| if (( r < 0 )); then | |
| r=0 | |
| fi | |
| if (( g > 255 )); then | |
| g=255 | |
| fi | |
| if (( g < 0 )); then | |
| g=0 | |
| fi | |
| if (( b > 255 )); then | |
| b=255 | |
| fi | |
| if (( b < 0 )); then | |
| b=0 | |
| fi | |
| # Convert RGB to hex | |
| current_color="$(printf "%02x%02x%02x" "$r" "$g" "$b")" | |
| # Convert the brightness from number to percentage. | |
| # openrgb accepts percentage instead of absolute value. | |
| # + 1 is a workaround for round off during setting the brightness | |
| # You may want to remove it if your hardware does not need it | |
| current_brightness="$(( "$(cat "$brightness_file")" * 100 / "$(cat "$maxbrightness_file")" + 1 ))" | |
| openrgb -m static -c "$current_color" -b "$current_brightness" > /dev/null | |
| sleep "$interval" | |
| i=$((i - 1)) | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment