Last active
January 22, 2016 05:39
-
-
Save dheaney/194fc0367ff96ce824ce to your computer and use it in GitHub Desktop.
Control MacBook screen brightness with arrow keys on 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
# -*- coding: utf-8 -*- | |
# Written by David Heaney on 21 January 2016 | |
# This software is in the public domain. | |
import curses | |
stdscr = curses.initscr() | |
curses.noecho() | |
curses.cbreak() | |
stdscr.keypad(1) | |
brightness = None | |
with open('/sys/class/backlight/intel_backlight/brightness', 'r') as f: | |
brightness = int(f.read()) | |
f.close() | |
def main(): | |
global brightness | |
while True: | |
stdscr.clear() | |
stdscr.addstr(0,2, "^") | |
stdscr.addstr(1,(2 if brightness == 0 else 4 - len(str(brightness))), str(brightness)) | |
stdscr.addstr(2,2, "v") | |
stdscr.refresh() | |
c = stdscr.getch() | |
if c == curses.KEY_UP: | |
brightness += 25 | |
if brightness >= 1388: brightness = 1388 | |
elif c == curses.KEY_DOWN: | |
brightness -= 25 | |
if brightness <= 0: brightness = 0 | |
else: | |
continue | |
with open('/sys/class/backlight/intel_backlight/brightness', 'w') as f: | |
f.write(str(brightness)) | |
f.close() | |
if __name__ == '__main__': | |
try: | |
main() | |
except KeyboardInterrupt: | |
curses.endwin() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment