Created
July 29, 2014 19:44
-
-
Save egcodes/96bc6d773429f0c68a16 to your computer and use it in GitHub Desktop.
Automatic backlight control for ubuntu
This file contains 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
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