Skip to content

Instantly share code, notes, and snippets.

@ManuelSchneid3r
Last active January 16, 2021 13:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ManuelSchneid3r/2e6ba00070d1c8e1e811a529c83ecbea to your computer and use it in GitHub Desktop.
Save ManuelSchneid3r/2e6ba00070d1c8e1e811a529c83ecbea to your computer and use it in GitHub Desktop.
Cinnamon Auto Dark Mode
#!/bin/env python3
from astral import sun
from astral.geocoder import lookup, database
from datetime import datetime as dt
from pathlib import Path
from pytz import timezone
from subprocess import call
# Config
brightness_day=95
brightness_night=50
cmd="0x10" # Brightness (Dell U2414H) > ddcutil capabilites
locationInfo = lookup("Berlin", database())
now = dt.now(timezone(locationInfo.timezone))
#now = dt(2021, 1, 16, 3, 0, 0, tzinfo=timezone(locationInfo.timezone)) # testing
sunrise = sun.sunrise(locationInfo.observer, now.today(), locationInfo.timezone)
sunset = sun.sunset(locationInfo.observer, now.today(), locationInfo.timezone)
# Compute brightness by some fancy sigmoid function
factor = 1/(1+10**(-(now-sunrise).total_seconds() / 3600)) \
- 1/(1+10**(-(now-sunset).total_seconds() / 3600))
print(f"{round(factor*100)}%")
brightness = round(brightness_night + factor * (brightness_day - brightness_night))
call(["ddcutil", "setvcp", cmd, str(brightness)])
if sunrise < now and now < sunset:
call(["sed", "-i", "s/-dark-/-light-/", Path.home()/".atom/config.cson"]) # Atom
call(["gsettings", "set", "org.cinnamon.theme", "name", "Arc"]) # Panel
call(["gsettings", "set", "org.cinnamon.desktop.wm.preferences", "theme", "Arc-Lighter"]) # Window manager
call(["gsettings", "set", "org.cinnamon.desktop.interface", "gtk-theme", "Arc-Lighter"]) # Controls
else: # night
call(["sed", "-i", "s/-light-/-dark-/", Path.home()/".atom/config.cson"]) # Atom
call(["gsettings", "set", "org.cinnamon.theme", "name", "Arc-Dark"]) # Panel
call(["gsettings", "set", "org.cinnamon.desktop.wm.preferences", "theme", "Arc-Dark"]) # Window manager
call(["gsettings", "set", "org.cinnamon.desktop.interface", "gtk-theme", "Arc-Dark"]) # Controls
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment