Skip to content

Instantly share code, notes, and snippets.

@lansing
Created May 17, 2019 21:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lansing/035fd659877abd300f715b544bfd36af to your computer and use it in GitHub Desktop.
Save lansing/035fd659877abd300f715b544bfd36af to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import subprocess
import sys
import re
from subprocess import Popen, PIPE, STDOUT
FILENAME = "/tmp/last_bright"
INC_ABS = 6
if len(sys.argv) < 2:
print("usage: bright.py -u/-d")
exit(-1)
if sys.argv[1] == "-u":
inc = INC_ABS
elif sys.argv[1] == "-d":
inc = -INC_ABS
else:
print("usage: bright.py -u/-d")
exit(-1)
try:
with open(FILENAME, "r") as f:
current_lvl = int(f.read())
except:
current_lvl_str = subprocess.check_output(['ddcutil', '-d', '1', 'getvcp', '10']).decode()
current_lvl = int(re.search(r'current value =\W+(\d+)', current_lvl_str).group(1))
next_lvl = current_lvl + inc
if next_lvl < 0:
next_lvl = 0
Popen(['ddcutil', '-d', '1', 'setvcp', '10', str(next_lvl)], stdin=None, stdout=None, stderr=None, close_fds=True, shell=False)
with open(FILENAME, 'w') as f:
f.write(str(next_lvl))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment