Skip to content

Instantly share code, notes, and snippets.

@kootenpv
Created May 11, 2017 08:38
Show Gist options
  • Save kootenpv/813c0016eb0ba85fa7b438c07b65f31e to your computer and use it in GitHub Desktop.
Save kootenpv/813c0016eb0ba85fa7b438c07b65f31e to your computer and use it in GitHub Desktop.
Auto brightness hack for OSX
# add keyboard brightness
import time
from datetime import datetime
SLEEP_TIME = 0.5
def write(n):
with open("/sys/class/backlight/gmux_backlight/brightness", "w") as f:
#print("new", n)
f.write(str(n))
with open("/sys/class/backlight/gmux_backlight/max_brightness") as f:
max_v = f.read()
print("running brightness, did you run with root?")
while True:
with open("/sys/devices/platform/applesmc.768/light") as f:
v = int(f.read()[1:-1].split(",")[0])
#print("old", v)
if v < 10:
# do not do comparison constantly
hour = datetime.now().hour
if hour > 22 or hour < 8:
write(100)
else:
write(300)
else:
write(max_v)
time.sleep(SLEEP_TIME)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment