Add 'dots/' from commit 'f64b634dd8fbb2c8a2898c3b9d0acc9452e4d966'
git-subtree-dir: dots git-subtree-mainline:2ad98cde17git-subtree-split:f64b634dd8
This commit is contained in:
51
dots/.bin/screen-temperature
Executable file
51
dots/.bin/screen-temperature
Executable file
@@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
import subprocess
|
||||
|
||||
DEFAULT_TEMPERATURE = 3500
|
||||
|
||||
try:
|
||||
with open('/tmp/temperature', 'r') as temp_file:
|
||||
current_temperature = int(temp_file.read())
|
||||
except FileNotFoundError:
|
||||
current_temperature = DEFAULT_TEMPERATURE
|
||||
|
||||
# If no argument is given print the current temperature
|
||||
if len(sys.argv) == 1:
|
||||
print(current_temperature)
|
||||
sys.exit(0)
|
||||
elif len(sys.argv) != 2:
|
||||
print("""
|
||||
Usage:
|
||||
|
||||
screen-temperature
|
||||
print current temperature
|
||||
|
||||
screen-temperature <temperature>
|
||||
set screen temperature to <temperature>
|
||||
|
||||
screen-temperature <+|-><temperature>
|
||||
increase or decrease screen temperature by <temperature>
|
||||
""")
|
||||
sys.exit(1)
|
||||
|
||||
temperature_change = sys.argv[1]
|
||||
|
||||
if temperature_change.startswith("+"):
|
||||
new_temperature = current_temperature + int(temperature_change[1:])
|
||||
elif temperature_change.startswith("-"):
|
||||
new_temperature = current_temperature - int(temperature_change[1:])
|
||||
else:
|
||||
new_temperature = int(temperature_change)
|
||||
|
||||
try:
|
||||
subprocess.run(["redshift", "-O", str(new_temperature), "-P"], check=True)
|
||||
with open('/tmp/temperature', 'w') as temp_file:
|
||||
temp_file.write(str(new_temperature) + '\n')
|
||||
# Send notification
|
||||
subprocess.run(
|
||||
["notify-send", str(new_temperature) + "K"])
|
||||
except subprocess.CalledProcessError:
|
||||
print("Error: could not set screen temperature.")
|
||||
sys.exit(1)
|
||||
Reference in New Issue
Block a user