Skip to content

Instantly share code, notes, and snippets.

@davesque
Created December 20, 2012 00:22
Show Gist options
  • Save davesque/4341997 to your computer and use it in GitHub Desktop.
Save davesque/4341997 to your computer and use it in GitHub Desktop.
Adjusts the brightness of the laptop display
#!/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)
@davesque
Copy link
Author

usage: bright [-h] level

Adjusts the brightness of the laptop display.

positional arguments:
  level       Level of brightness from 1 to 10.

optional arguments:
  -h, --help  show this help message and exit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment