The officially official Devuan Forum!

You are not logged in.

#1 2021-10-11 13:39:12

hevidevi
Member
Registered: 2021-09-17
Posts: 230  

simple day night / light dark theme change script -gtk2 and 3.

using gtkrc-2.0 - see second post for gtk3 script.

i use startx so use .xinitrc to autostart scripts there.

This just changes the .gtkrc-2.0 theme file in $HOME to match the time of day, so any time after 6 am is a light theme and any time after 6pm is a dark theme, i think i got the script correct as it is using a while loop that checks every 30 minutes?  It just comments out the appropriate gtk and icon theme for the time of day. I thought someone here might find it useful.

#!/bin/sh
get_date=$(date +%k%M)
get_theme () {
if [ "$get_date" -lt "1759" ]; then
        printf "$(sed -i -e '1,2s/#//' "$HOME"/.gtkrc-2.0 && sed -i '3,4s/#//' "$HOME"/.gtkrc-2.0)"; # Theme Reset
	printf "$(sed -i -e '1,2s/#//' "$HOME"/.gtkrc-2.0 && sed -i '3,4s/./#&/' "$HOME"/.gtkrc-2.0)"; # Light Theme
elif [ "$get_date" -gt "1800" ]; then
        printf "$(sed -i -e '1,2s/#//' "$HOME"/.gtkrc-2.0 && sed -i '3,4s/#//' "$HOME"/.gtkrc-2.0)" # Theme Reset
        printf "$(sed -i -e '3,4s/#//' "$HOME"/.gtkrc-2.0 && sed -i '1,2s/./#&/' "$HOME"/.gtkrc-2.0)" # Dark Theme
fi
}
while true; do
        get_theme
        sleep 1800s
done

so if you have a similar gtkrc-2.0 file with light dark themes you can using the startup script. I dont bother much with gtk3 apps, firefox is set to dark but it only affects the firefox areas of the app. I also dont use theme setters like lxappearance and do it manually.

Light mode.

gtk-theme-name="Greybird"
gtk-icon-theme-name="Papirus"
#gtk-theme-name="Greybird-dark"
#gtk-icon-theme-name="Papirus-Dark"

gtk-font-name="Sans 11"
gtk-cursor-theme-name="DMZ-White"
gtk-cursor-theme-size=0
gtk-toolbar-style=GTK_TOOLBAR_ICONS
gtk-toolbar-icon-size=GTK_ICON_SIZE_LARGE_TOOLBAR
gtk-button-images=1
gtk-menu-images=1
gtk-enable-event-sounds=1
gtk-enable-input-feedback-sounds=1
gtk-xft-antialias=1
gtk-xft-hinting=1
gtk-xft-hintstyle="hintfull"

Dark mode

#gtk-theme-name="Greybird"
#gtk-icon-theme-name="Papirus"
gtk-theme-name="Greybird-dark"
gtk-icon-theme-name="Papirus-Dark"

gtk-font-name="Sans 11"
gtk-cursor-theme-name="DMZ-White"
gtk-cursor-theme-size=0
gtk-toolbar-style=GTK_TOOLBAR_ICONS
gtk-toolbar-icon-size=GTK_ICON_SIZE_LARGE_TOOLBAR
gtk-button-images=1
gtk-menu-images=1
gtk-enable-event-sounds=1
gtk-enable-input-feedback-sounds=1
gtk-xft-antialias=1
gtk-xft-hinting=1
gtk-xft-hintstyle="hintfull"

Edited: Updated script, now working as it should.

Last edited by hevidevi (2021-10-12 09:10:27)

Offline

#2 2021-10-12 09:08:07

hevidevi
Member
Registered: 2021-09-17
Posts: 230  

Re: simple day night / light dark theme change script -gtk2 and 3.

Made a script for the gtk3 settings.ini as well, pretty much similar to gtk2rc.
There is some prior editing to be done to the settings.ini which includes setting up the ini file as follow with your favorite light and dark icons and gtk theme. See bold text in quote, lines 2 and 3  is the light theme and lines 4 and 5 are the dark theme.

[Settings]
gtk-application-prefer-dark-theme=false
gtk-icon-theme-name=Papirus
gtk-application-prefer-dark-theme=true
gtk-icon-theme-name=Papirus-Dark

gtk-button-images=1
gtk-cursor-theme-name=DMZ-White
gtk-cursor-theme-size=16
gtk-decoration-layout=icon:minimize,maximize,close
gtk-enable-animations=true
gtk-enable-event-sounds=0
gtk-enable-input-feedback-sounds=0
gtk-font-name=Sans 12
gtk-menu-images=1
gtk-primary-button-warps-slider=false
gtk-theme-name=Greybird
gtk-toolbar-icon-size=GTK_ICON_SIZE_LARGE_TOOLBAR
gtk-toolbar-style=GTK_TOOLBAR_ICONS
gtk-xft-antialias=1
gtk-xft-hinting=1
gtk-xft-hintstyle=hintfull
gtk-xft-rgba=rgb

The script.

#!/bin/sh
get_date=$(date +%k%M)
get_theme () {
if [ "$get_date" -lt "1759" ]; then
        printf "$(sed -i -e '2,3s/#//' "$HOME"/.config/gtk-3.0/settings.ini && sed -i '4,5s/#//' "$HOME"/.config/gtk-3.0/settings.ini)"; # Theme Reset
	printf "$(sed -i -e '2,3s/#//' "$HOME"/.config/gtk-3.0/settings.ini && sed -i '4,5s/./#&/' "$HOME"/.config/gtk-3.0/settings.ini)"; # Light Theme
elif [ "$get_date" -gt "1800" ]; then
        printf "$(sed -i -e '2,3s/#//' "$HOME"/.config/gtk-3.0/settings.ini && sed -i '4,5s/#//' "$HOME"/.config/gtk-3.0/settings.ini)" # Theme Reset
        printf "$(sed -i -e '4,5s/#//' "$HOME"/.config/gtk-3.0/settings.ini && sed -i '2,3s/./#&/' "$HOME"/.config/gtk-3.0/settings.ini)" # Dark Theme
fi
}
while true; do
        get_theme
        sleep 1800s
done

Offline

Board footer