Last active
January 25, 2023 19:32
-
-
Save laszukdawid/8777bc3c211a4e78f1998be0125f9e4d to your computer and use it in GitHub Desktop.
Set of commands and files to enable timed theme (dark/light) change
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kretyn@meland:~/$ mkdir -p ~/.config/systemd/user | |
kretyn@meland:~/$ mkdir -p ~/.scripts | |
kretyn@meland:~/$ cd ~/.config/systemd/user | |
kretyn@meland:~/.config/systemd/user$ cat light.service | |
[Unit] | |
Description=Automatically change the "Window Theme" to "light" in the morning. | |
[Service] | |
Environment=DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus | |
ExecStart=/home/kretyn/.scripts/profile_changer.sh light | |
kretyn@meland:~/.config/systemd/user$ cat light.timer | |
[Unit] | |
Description=Automatically change the "Window Theme" to "light" in the morning. | |
[Timer] | |
OnCalendar=*-*-* 06:00:00 | |
Persistent=true | |
[Install] | |
WantedBy=default.target | |
kretyn@meland:~/.config/systemd/user$ cat dark.service | |
[Unit] | |
Description=Automatically change the "Window Theme" to "dark" in the evening. | |
[Service] | |
Environment=DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus | |
ExecStart=/home/kretyn/.scripts/profile_changer.sh dark | |
kretyn@meland:~/.config/systemd/user$ cat dark.timer | |
[Unit] | |
Description=Automatically change the "Window Theme" to "dark" in the evening. | |
[Timer] | |
OnCalendar=*-*-* 19:00:00 | |
Persistent=true | |
[Install] | |
WantedBy=default.target | |
kretyn@meland:~/$ cat ~/.scripts/profile_changer.sh | |
#!/bin/bash | |
get_uuid() { | |
# Print the UUID linked to the profile name sent in parameter | |
local profile_name=$1 | |
profiles=($(gsettings get org.gnome.Terminal.ProfilesList list | tr -d "[]\',")) | |
for i in ${!profiles[*]} | |
do | |
local uuid="$(dconf read /org/gnome/terminal/legacy/profiles:/:${profiles[i]}/visible-name)" | |
if [[ "${uuid,,}" = "'${profile_name,,}'" ]] | |
then echo "${profiles[i]}" | |
return 0 | |
fi | |
done | |
echo "$profile_name" | |
} | |
if [ $1 == "dark" ]; then | |
THEME='Yaru-dark' | |
elif [ $1 == "light" ]; then | |
THEME='Yaru-light' | |
fi | |
UUID=$(get_uuid $1) | |
/usr/bin/gsettings set org.gnome.desktop.interface gtk-theme $THEME | |
/usr/bin/gsettings set org.gnome.Terminal.ProfilesList default $UUID | |
kretyn@meland:~$ systemctl --user daemon-reload | |
kretyn@meland:~$ systemctl --user enable dark.timer light.timer | |
kretyn@meland:~$ systemctl --user start dark.timer light.timer |
Neat @W-Floyd, Thanks! :)
I had problem to execute this but it turned out that the xmllint
isn't installed by default. Needed to install libxml2-utils
(sudo apt install libxml2-utils
).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It took me a while to figure it out, but you can add this to change all currently running terminal windows to the correct theme also:
Note that this only changes the active terminal tab.