Skip to content

Instantly share code, notes, and snippets.

@phagenlocher
Created November 4, 2016 21:40
Show Gist options
  • Select an option

  • Save phagenlocher/21cd09b9012c2c509db976d306f2115c to your computer and use it in GitHub Desktop.

Select an option

Save phagenlocher/21cd09b9012c2c509db976d306f2115c to your computer and use it in GitHub Desktop.
Script to change screenbrightness on a Thinkpad T410
#!/usr/bin/python3
import sys
def readFile(path):
with open(path, 'r', encoding='utf-8') as file:
return int(file.read())
def writeFile(path, value):
with open(path, 'w', encoding='utf-8') as file:
file.write(str(value))
CHANGE = 300
MAXBRIGHTNESS = readFile('/sys/class/backlight/intel_backlight/max_brightness')
CURRENTBRIGHT = readFile('/sys/class/backlight/intel_backlight/brightness')
newBrightness = CURRENTBRIGHT
if '-get' in sys.argv:
print('Maximum brightness:', MAXBRIGHTNESS)
print('Current brightness:', CURRENTBRIGHT)
if not '-v' in sys.argv:
def print(*args):
pass
if '-inc' in sys.argv:
newBrightness = min(MAXBRIGHTNESS, CURRENTBRIGHT + CHANGE)
if '-dec' in sys.argv:
newBrightness = max(0, CURRENTBRIGHT - CHANGE)
if '-set' in sys.argv:
percent = int(sys.argv[sys.argv.index('-set')+1])
if percent >= 0:
if percent > 100:
percent = 100
print('Setting to {}%'.format(percent))
newBrightness = int(MAXBRIGHTNESS * (percent / 100))
if newBrightness != CURRENTBRIGHT:
writeFile('/sys/class/backlight/intel_backlight/brightness', newBrightness)
print('New brightness:', newBrightness)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment