Last active
April 19, 2019 16:46
-
-
Save YakBarber/41f71f066896b0310cc5c0de0ec77d57 to your computer and use it in GitHub Desktop.
Small script to control brightness on laptop with Intel chipset running Ubuntu. Fn brightness keys and xbacklight stopped working, but this worked. Pass an int between 0 and 100 representing the percent brightness you want. Call without args to get current percentage.
This file contains hidden or 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 python3 | |
import os | |
import sys | |
import subprocess | |
from pathlib import Path | |
if os.geteuid()!=0: | |
args = ['sudo'] + sys.argv | |
os.execlp('sudo',*args) | |
bpath = Path("/sys/class/backlight/intel_backlight/") | |
bmax = int((bpath/"max_brightness").read_text()) | |
bcur = int((bpath/"brightness").read_text()) | |
if len(sys.argv)<2: | |
print(round(bcur/bmax*100)) | |
sys.exit(0) | |
else: | |
perc = int(sys.argv[1]) | |
val = str(int(perc/100*bmax)) | |
cmd = "echo " + val + " > " + str(bpath/"brightness") | |
print(subprocess.getoutput(cmd)) | |
sys.exit(0) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment