brightness/brightness.py

28 lines
751 B
Python
Raw Normal View History

2019-01-06 20:46:09 +00:00
#!/usr/bin/env python3
import os, sys, string, subprocess
def main():
2019-01-06 20:53:00 +00:00
cmd = "xrandr --verbose | grep {} -A 5 | grep Brightness | cut -f 2 -d ' '".format(display())
2019-01-06 20:46:09 +00:00
brightness = float(subprocess.getoutput(cmd))
if sys.argv[1] == "+" and brightness < 1:
brightness += .25
elif sys.argv[1] == "-" and brightness > 0:
brightness -= .25
2019-01-06 20:53:00 +00:00
os.system("xrandr --output {} --brightness {}".format(display(), brightness))
2019-01-06 20:46:09 +00:00
2019-01-06 20:53:00 +00:00
def display():
2019-01-06 20:46:09 +00:00
cmd = "xdotool getmouselocation --shell | head -n -3 | sed 's/[^0-9]*//g'"
cmd = subprocess.getoutput(cmd)
2019-01-06 20:53:00 +00:00
if int(cmd) < 2560:
2019-01-06 20:46:09 +00:00
return "DP-1"
return "DP-2"
if len(sys.argv) <= 1:
print("Usage: {} [+|-]".format(sys.argv[0]))
sys.exit(1)
else:
main()