Ordered Chaotic Discussions

Macbook Air 2012 Keyboard Breathing Effect


(The Lazy) #1

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


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
        while [ $counter -ge 0 ] #Increment Counter
                echo $counter > $LED
                (( counter++ ))
                sleep $SLEEP
                if [ $counter = 255 ]

        while [ $counter -le 255 ] #Decrement counter
                echo $counter > $LED
                (( counter-- ))
                sleep $SLEEP
                if [ $counter = 0 ]


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

The Lounge 0001 [From the Beginning]

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.

(The Lazy) #3

Yep. Timing worked itself out because the lower end brightness values have much less fine grain control so the breathing effect speeds up on its own :smiley:


lel neat that it worked out like that, its a feature not a bug

(The Lazy) #5

yep. The only bad thing about this is that it uses almost 10% cpu to run. Im gonna reserve this down to being bash


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.

(The Lazy) #7

no idea. im guessing most of the wasted cpu is down to massive amount of open() and close() calls im making to that file


ah if thats the case then probably not. is a shame though because it looks really good :frowning:


@Dje4321 just a quick question, What is a Macboor Air?

(The Lazy) #10

Apple “thin and light” models of macbooks



What is this though XD


if that was attempt at pun 1/10 nice try tho

i see now lol
english, strikes again

(The Lazy) #13

me not good at spelling


Should talk to @Main_Main about that :stuck_out_tongue:

(🤢I don't english good 🤮) #15

I know the struggles, I empathize with your plight