brightness/brightness.py

38 lines
1.1 KiB
Python
Executable File

#!/usr/bin/env python3
import os, sys, string, subprocess, json
def main():
cmd = "xrandr --verbose | grep {} -A 5 | grep Brightness | cut -f 2 -d ' '".format(display())
brightness = float(subprocess.getoutput(cmd))
if sys.argv[1] == "+" and brightness < 1:
brightness += .25
elif sys.argv[1] == "-" and brightness > 0:
brightness -= .25
os.system("xrandr --output {} --brightness {}".format(display(), brightness))
def display():
cmd = "xdotool getmouselocation --shell | head -n -3 | cut -d'=' -f2-"
cmd = subprocess.getoutput(cmd)
#print(getDisplay()['display0']);
if int(cmd) < 2560:
return getDisplay()['display1']
return getDisplay()['display0']
def getDisplay():
root_dir = os.path.dirname(os.path.realpath(__file__))
json_path = os.path.join(root_dir, 'settings.json')
with open(json_path, 'r') as json_data:
settings = json.load(json_data)
json_data.close()
return settings
if len(sys.argv) <= 1:
print("Usage: {} [+|-]".format(sys.argv[0]))
sys.exit(1)
else:
main()