Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Set of commands and files to enable timed theme (dark/light) change
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.