home · archive · links · projects

brightness.py

Adjust linux screen brightness

#!/usr/bin/env python3

import os
import sys

dir = "/sys/class/backlight/amdgpu_bl0"
maxb = 1000

with open(dir + '/max_brightness') as fp:
    maxb = int(fp.read())

i = int(sys.argv[1])

if i < 10: i = 10
if i > 100: i = 100

value = maxb * i / 100

cmd = 'echo ' + str(int(value)) + ' | sudo tee /sys/class/backlight/amdgpu_bl0/brightness > /dev/null'
os.system(cmd)

© Licensed under CC BY-NC-SA 4.0 if not specified otherwise.
Email: dzshy [at] outlook [dot] com