-
Notifications
You must be signed in to change notification settings - Fork 27
DE Night Mode scripts
Federico Di Pierro edited this page Feb 28, 2021
·
4 revisions
An often-requested feature is the possibility to change DE theme automatically, shifting from a light one during the day, to a dark one, during the night.
While Clight won't add support for DE-specific code, the feature can be achieved quite easily through its bus api: you can listen on "Time" PropertiesChanged
signal that is emitted at Sunrise and Sunset.
Such a script could look like:
#!/usr/bin/env python
import dbus
import subprocess
from gi.repository import GLib
from dbus.mainloop.glib import DBusGMainLoop
old_time = -1; # 0 -> day, 1 -> night
def handle_time_change(*args):
global old_time
if 'DayTime' in args[1] and old_time != args[1]['DayTime']:
if args[1]['DayTime'] == 1:
subprocess.Popen(["lookandfeeltool", "-a", "org.kde.breezedark.desktop"])
elif args[1]['DayTime'] == 0:
subprocess.Popen(["lookandfeeltool", "-a", "org.kde.breeze.desktop"])
old_time = args[1]['DayTime']
DBusGMainLoop(set_as_default=True)
bus = dbus.SessionBus()
bus.add_signal_receiver(
handle_time_change,
'PropertiesChanged',
'org.freedesktop.DBus.Properties',
path='/org/clight/clight'
)
loop = GLib.MainLoop().run()
#!/usr/bin/env python
import dbus
import subprocess
from gi.repository import GLib
from dbus.mainloop.glib import DBusGMainLoop
old_time = -1; # 0 -> day, 1 -> night
def handle_time_change(*args):
global old_time
if 'DayTime' in args[1] and old_time != args[1]['DayTime']:
if args[1]['DayTime'] == 1:
# Applications
subprocess.Popen(["gsettings set org.gnome.desktop.interface gtk-theme", "Matcha-dark-sea"])
# Cursor
subprocess.Popen(["gsettings set org.gnome.desktop.interface cursor-theme", "xcursor-breeze-snow"])
# Icons
subprocess.Popen(["gsettings set org.gnome.desktop.interface icon-theme", "Papirus-Dark-Maia"])
# Shell
subprocess.Popen(["gsettings set org.gnome.shell.extensions.user-theme name", "Matcha-dark-sea"])
elif args[1]['DayTime'] == 0:
# Applications
subprocess.Popen(["gsettings set org.gnome.desktop.interface gtk-theme", "Matcha-sea"])
# Cursor
subprocess.Popen(["gsettings set org.gnome.desktop.interface cursor-theme", "xcursor-breeze"])
# Icons
subprocess.Popen(["gsettings set org.gnome.desktop.interface icon-theme", "Papirus-Maia"])
# Shell
subprocess.Popen(["gsettings set org.gnome.shell.extensions.user-theme name", "Matcha-sea"])
old_time = args[1]['DayTime']
DBusGMainLoop(set_as_default=True)
bus = dbus.SessionBus()
bus.add_signal_receiver(
handle_time_change,
'PropertiesChanged',
'org.freedesktop.DBus.Properties',
path='/org/clight/clight'
)
loop = GLib.MainLoop().run()
#!/usr/bin/env python
import dbus
import subprocess
from gi.repository import GLib
from dbus.mainloop.glib import DBusGMainLoop
old_time = -1; # 0 -> day, 1 -> night
def handle_time_change(*args):
global old_time
if 'DayTime' in args[1] and old_time != args[1]['DayTime']:
if args[1]['DayTime'] == 1:
# Window borders
subprocess.Popen(["gsettings set org.cinnamon.desktop.wm.preferences theme", "Matcha-dark-sea"])
# Icons
subprocess.Popen(["gsettings set org.cinnamon.desktop.interface icon-theme", "Papirus-Dark-Maia"])
# Controls
subprocess.Popen(["gsettings set org.cinnamon.desktop.interface gtk-theme", "Matcha-dark-sea"])
# Mouse Pointer
subprocess.Popen(["gsettings set org.cinnamon.desktop.interface cursor-theme", "xcursor-breeze-snow"])
# Desktop
subprocess.Popen(["gsettings set org.cinnamon.theme name", "Matcha-dark-sea"])
elif args[1]['DayTime'] == 0:
# Window borders
subprocess.Popen(["gsettings set org.cinnamon.desktop.wm.preferences theme", "Matcha-sea"])
# Icons
subprocess.Popen(["gsettings set org.cinnamon.desktop.interface icon-theme", "Papirus-Maia"])
# Controls
subprocess.Popen(["gsettings set org.cinnamon.desktop.interface gtk-theme", "Matcha-sea"])
# Mouse Pointer
subprocess.Popen(["gsettings set org.cinnamon.desktop.interface cursor-theme", "xcursor-breeze"])
# Desktop
subprocess.Popen(["gsettings set org.cinnamon.theme name", "Matcha-sea"])
old_time = args[1]['DayTime']
DBusGMainLoop(set_as_default=True)
bus = dbus.SessionBus()
bus.add_signal_receiver(
handle_time_change,
'PropertiesChanged',
'org.freedesktop.DBus.Properties',
path='/org/clight/clight'
)
loop = GLib.MainLoop().run()
#!/usr/bin/env python
import dbus
import subprocess
from gi.repository import GLib
from dbus.mainloop.glib import DBusGMainLoop
old_time = -1; # 0 -> day, 1 -> night
def handle_time_change(*args):
global old_time
if 'Time' in args[1] and old_time != args[1]['Time']:
if args[1]['Time'] == 1:
# GTK theme
subprocess.Popen(["xfconf-query -c xsettings -p /Net/ThemeName -s", "Matcha-dark-sea"])
# Xfwm4 theme
subprocess.Popen(["xfconf-query -c xfwm4 -p /general/theme -s", "Matcha-dark-sea"])
# Cursor theme
subprocess.Popen(["xfconf-query -c xsettings -p /Gtk/CursorThemeName -s", "xcursor-breeze-snow"])
# Icon theme
subprocess.Popen(["xfconf-query -c xsettings -p /Net/IconThemeName -s", "Papirus-Dark-Maia"])
elif args[1]['Time'] == 0:
# GTK theme
subprocess.Popen(["xfconf-query -c xsettings -p /Net/ThemeName -s", "Matcha-sea"])
# Xfwm4 theme
subprocess.Popen(["xfconf-query -c xfwm4 -p /general/theme -s", "Matcha-sea"])
# Cursor theme
subprocess.Popen(["xfconf-query -c xsettings -p /Gtk/CursorThemeName -s", "xcursor-breeze"])
# Icon theme
subprocess.Popen(["xfconf-query -c xsettings -p /Net/IconThemeName -s", "Papirus-Maia"])
old_time = args[1]['Time']
DBusGMainLoop(set_as_default=True)
bus = dbus.SessionBus()
bus.add_signal_receiver(
handle_time_change,
'PropertiesChanged',
'org.freedesktop.DBus.Properties',
path='/org/clight/clight'
)
loop = GLib.MainLoop().run()
Thanks @yochananmarqos for Gnome and Cinnamon scripts!
You can even just change your wallpaper with similar scripts, or whatever you'll come up with!
Happy scripting!