blob: b1b29bfdde3e1b00bef036e78fbc68f2a3888725 (
plain)
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
44
45
46
47
|
#!/usr/bin/python3
#
# Dims your display using brightnessctl
#
import subprocess
import os
import sys
default_multiplier = 0.1
def run(cmd):
print(cmd)
process = subprocess.run(
cmd.split(" "),
capture_output=True,
text = True
)
return process.stdout.strip("\n")
def brightnessctl(args):
template = "brightnessctl {args}"
cmd = template.format(
args = args
)
return run(cmd)
def multiplier():
if len(sys.argv) == 2:
return float(sys.argv[1])
else:
return float(default_multiplier)
path = "/tmp/brightness-" + str(multiplier())
if os.path.exists(path):
with open(path, "r") as file:
brightnessctl("set {brightness}".format(brightness=file.readlines()[0]))
os.remove(path)
else:
current_brightness = brightnessctl("get")
with open(path, "w") as file:
file.write(current_brightness)
new_brightness = int(current_brightness) * multiplier()
brightnessctl("set {new_brightness}".format(new_brightness=new_brightness))
|