-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscreen_py_version
executable file
·29 lines (24 loc) · 1.05 KB
/
screen_py_version
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
#!/usr/bin/python3
# os for executing command and sys for geting argumant ('up' or 'down')
import sys, os
def run():
stream = os.popen('xrandr --prop --verbose | grep -A10 " connected" | grep "Brightness"')
dev = os.popen('xrandr --prop --verbose | grep -A10 " connected primary"').read().split()[0]
b = float(stream.read().split()[1])
# now we have current brightness as a float var in b
check = sys.argv[1]
if check == 'up' and b < 1.0:
b += 0.1
os.system(f'xrandr --output {dev} --brightness {b}')
# changing brightness
elif check == 'down' and b > 0.1:
b -= 0.1
os.system(f'xrandr --output {dev} --brightness {b}')
os.system('notify-send "Screen Brightness: {:.0f}%"'.format((b / 1) * 100))
# showing the changed value brightness to user
if __name__ == '__main__':
check_for_xrandr = os.popen('which xrandr').read()
if check_for_xrandr != '':
run()
else:
os.system('notify-send "You don\'t have xrandr, install by: \n[apt/dnf] install xrandr\npacman -Sy xrandr"')