Skip to content

Instantly share code, notes, and snippets.

@Difrex
Created March 5, 2019 08:19
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 Difrex/c685388449852446b00e42f3bfeeca11 to your computer and use it in GitHub Desktop.
Save Difrex/c685388449852446b00e42f3bfeeca11 to your computer and use it in GitHub Desktop.

theme_reloader.py

#!/usr/bin/env python

from datetime import datetime
from os import popen, environ
import time


times = {
    "from": 9,
    "to": 18,
    "current": None,
}


def switch_theme(theme):
    print("Switching to the " + theme + " theme")
    stdout = popen("/home/difrex/.config/i3/theme_set.py " + theme)
    print(stdout)
    times["current"] = theme


def loop():
    while True:
        if environ.get("DISPLAY", False):
            current_time = datetime.now()
            # Light theme
            if current_time.hour > times["from"] and current_time.hour < times["to"]:
                if not times["current"] or times["current"] != "light":
                    switch_theme("light")
            # Dark theme
            if current_time.hour > times["to"] or current_time.hour < times["from"]:
                if not times["current"] or times["current"] != "dark":
                    switch_theme("dark")
            time.sleep(10 * 60)


if __name__ == "__main__":
    loop()

theme_reloader.service

[Unit]
After=emacs.service
Description=Dark and Light theme reloader

[Service]
Type=simple
ExecStart=/home/difrex/.config/i3/theme_reloader.py

[Install]
WantedBy=default.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment