Skip to content

Instantly share code, notes, and snippets.

@egcodes
Created July 29, 2014 19:44
Show Gist options
  • Save egcodes/96bc6d773429f0c68a16 to your computer and use it in GitHub Desktop.
Save egcodes/96bc6d773429f0c68a16 to your computer and use it in GitHub Desktop.
Automatic backlight control for ubuntu
import os, time
import pyscreenshot as ImageGrab
while True:
screen = ImageGrab.grab()
dark = 0
bright = 0
for i in screen.getdata():
if i[0] > 150 and i[1] > 150 and i[2] > 150:
bright += 1
else:
dark += 1
# calc backlight percent
percent = 100 - (bright * 100) / (bright + dark)
print "Resolution", screen.size[0], 'x', screen.size[1], " -> setBacklight: %", percent
# set backlight
os.system("xbacklight -set %d"%percent)
time.sleep(3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment