Created
December 20, 2012 00:22
-
-
Save davesque/4341997 to your computer and use it in GitHub Desktop.
Adjusts the brightness of the laptop display
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
#!/usr/bin/env python | |
import argparse | |
from fractions import Fraction | |
MAX_BRIGHTNESS_FILE = '/sys/class/backlight/intel_backlight/max_brightness' | |
BRIGHTNESS_FILE = '/sys/class/backlight/intel_backlight/brightness' | |
if __name__ == '__main__': | |
parser = argparse.ArgumentParser(description='Adjusts the brightness of the laptop display.') | |
parser.add_argument('level', type=int, help='Level of brightness from 1 to 10.') | |
args = parser.parse_args() | |
with open(MAX_BRIGHTNESS_FILE, 'r') as f: | |
max_brightness = Fraction(f.read().strip()) | |
brightness_inc = max_brightness / 10 | |
level = min(max(args.level, 0), 10) | |
brightness = str(int(brightness_inc * level)) | |
with open(BRIGHTNESS_FILE, 'w') as f: | |
f.write(brightness) |
Author
davesque
commented
Dec 20, 2012
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment