Help scripting Caps lock on off status
Hey everyone. I have been using linux mint since a year and loved it. It just works without manual tinkering. But now, captivated by the tiling managers, i jumped to Cachy hyprland. It's interesting but doesn't have many basic functionalities like alerting user about Caps lock key status through sound. I took help of ai but it somehow spikes my cpu usage and i have to reboot to make it normal again. Here is the Script :
#!/bin/bash
# Target the specific caps lock directory (adjust if you have a specific one like input3::capslock)
LED_PATH=$(ls -d /sys/class/leds/*::capslock | head -n 1)
# Fallback paths for the sounds
SOUND_ON="/usr/share/sounds/freedesktop/stereo/dialog-information.oga"
SOUND_OFF="/usr/share/sounds/freedesktop/stereo/dialog-warning.oga"
# Read initial state
last_state=$(cat "$LED_PATH/brightness")
while true; do
# Instant raw read of the file system
current_state=$(cat "$LED_PATH/brightness")
if [ "$current_state" != "$last_state" ]; then
if [ "$current_state" -eq 1 ]; then
# Using pw-play or paplay with low-latency flags
pw-play "$SOUND_ON" &
else
pw-play "$SOUND_OFF" &
fi
last_state=$current_state
fi
# 20ms polling rate (0.02s) gives instant human response time
# without hurting CPU performance
sleep 0.02
done
Can you guys please help me out.