-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpolybar_backlight_ctrl.py
More file actions
executable file
·45 lines (32 loc) · 1.09 KB
/
polybar_backlight_ctrl.py
File metadata and controls
executable file
·45 lines (32 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/python3
import argparse
import subprocess
import sys
def main():
parser = argparse.ArgumentParser(description='Simple polybar backlight control script')
subparsers = parser.add_subparsers(dest="request")
subparsers.add_parser('get')
inc_parser = subparsers.add_parser('inc')
inc_parser.add_argument('val', type=int)
dec_parser = subparsers.add_parser('dec')
dec_parser.add_argument('val', type=int)
args = parser.parse_args()
if args.request == "get":
handle_get_request()
elif args.request == "inc":
handle_inc_request(args.val)
elif args.request == "dec":
handle_dec_request(args.val)
else:
parser.print_help()
def handle_get_request():
raw_out = subprocess.check_output(["light", "-G"])
out = raw_out.decode("utf8")
out = out.strip("\r\n")
sys.stdout.write(str(int(float(out))) + "%")
def handle_inc_request(value):
subprocess.check_call(["light", "-A", str(value)])
def handle_dec_request(value):
subprocess.check_call(["light", "-U", str(value)])
if __name__ == "__main__":
main()