So ive managed to get my macbook air 2012 backlit keyboard to have a breathing effect. This is done by writing values from 0-255 to the applesmc driver which controls the keyboard backlight
Here is the code that does it. It needs to be ran as root to access the driver
#!/bin/bash
SLEEP=0.005 #Delay for sleep. Controls how fast the breathing is
LED=/sys/devices/platform/applesmc.768/leds/smc::kbd_backlight/brightness #Points to where brightness is controlled
counter=$(cat $LED) #sets up the counter variable so that is used for keeping track of brightness
while true
do
while [ $counter -ge 0 ] #Increment Counter
do
echo $counter > $LED
(( counter++ ))
sleep $SLEEP
if [ $counter = 255 ]
then
break
fi
done
while [ $counter -le 255 ] #Decrement counter
do
echo $counter > $LED
(( counter-- ))
sleep $SLEEP
if [ $counter = 0 ]
then
break
fi
done
done
There is a slight problem with this implementation problem right now. It uses almost 10% cpu power to run which may not be the best thing. I reserve this problem as being a bash problem. I might try to rewrite this in python later and see if that helps out
Nice great work. In the video that effect looks so natural that you’d think it was a design feature build into the laptop. the breathing on my keyboard looks almost exactly like that with similar timing.
yea knowing bash possibly. would it not be an option to port it over to another shell like ash or zsh? Not sure if there would be much improvement though.
There is a slight problem with this implementation problem right now. It uses almost 10% cpu power to run which may not be the best thing.
If not, then I’d argue that using 10% of the CPU just for a keyboard backlight effect is kind of waste. Neat gimmick, but that’s a lot of CPU power.
Hey and welcome, I’ll try and go through the basic process of running this script.
Firstly copy the script and save it to file as something like breath.sh
Open a Terminal session and assign the execute permissions to the file with:
chmod +x breath.sh
Now you should be able to run the script with:
sudo ./breath.sh
Also as a side note as it wasn’t mentioned in the original post, I believe this script was designed to run on Linux and I’m not sure whether it will also work in macOS or if it has the same access to the smcdriver needed for this script to run. @Dje4321 who wrote this script should know more on this as I don’t have access to a device with macOS to test it.
I don’t believe so? Dje mention it might’ve been an issue with bash so it may have had an update in the last two years that makes this run better but I really can’t say.