How to change desktop theme periodically

here I wrote you some scripts to do random settings using gconf.

ChangeGTKTheme

#!/bin/bash
if [ "$1" == "random" ]; then
files=(~/.themes/*)
base=$(basename "${files[RANDOM % ${#files[@]}]}")
gconftool-2 --type=string -s /desktop/gnome/interface/gtk_theme $base
else
if [  "$1" == "" ];  then
    echo "Usage: $0 GTK_theme_name"
    echo "or $0 random  / for a random pick"
else
#GTK theme
gconftool-2 --type=string -s /desktop/gnome/interface/gtk_theme $1
 fi
fi

ChangeBackground

#!/bin/bash
if [ "$1" == "random" ]; then
files=(~/.backgrounds/*)
gconftool-2 -t str --set /desktop/gnome/background/picture_filename  "${files[RANDOM % ${#files[@]}]}"
else
if [  "$1" == "" ];  then
    echo "Usage: $0 path/to/background"
    echo "or $0 random  / for a random pick"
else
#Wallpaper
gconftool-2 -t str --set /desktop/gnome/background/picture_filename $1 
fi
fi

ChangeIcons

#!/bin/bash
if [ "$1" == "random" ]; then
files=(~/.icons/*)
base=$(basename "${files[RANDOM % ${#files[@]}]}")
gconftool-2 --type=string -s /desktop/gnome/interface/icon_theme  $base
else
if [  "$1" == "" ];  then
    echo "Usage: $0 icon_theme_name"
    echo "or $0 random  / for a random pick"
else
#Icons
gconftool-2 --type=string -s /desktop/gnome/interface/icon_theme $1
fi
fi

ChangeMetacityThemes

#!/bin/bash
if [ "$1" == "random" ]; then
files=(~/.themes/*)
base=$(basename "${files[RANDOM % ${#files[@]}]}")
gconftool-2 --type=string -s /apps/metacity/general/theme $base
else
if [  "$1" == "" ];  then
    echo "Usage: $0 metacity_theme_name"
    echo "or $0 random  / for a random pick"
else
#Metacity
gconftool-2 --type=string -s /apps/metacity/general/theme $1
fi
fi

Hope these help you.


Instead of writing a bash script you could do this all with cron. And if you're not a bash expert I'm guessing you're not a cron expert either so download Gnome-Schedule from the Ubuntu Software Center. That's basically a GUI for working with cron. Then just setup a task to run every hour that includes the following commands (you'd need a separate task for each command but they could run at the same time.

GTK theme:

gconftool-2 --type=string -s /desktop/gnome/interface/gtk_theme PUT_THE_THEME_NAME_HERE

Metacity:

gconftool-2 --type=string -s /apps/metacity/general/theme PUT_THE_THEME_NAME_HERE

Icons:

gconftool-2 --type=string -s /desktop/gnome/interface/icon_theme PUT_THE_ICON_THEME_NAME_HERE

Wallpaper:

gconftool-2 -t str --set /desktop/gnome/background/picture_filename "PUT_THE_PATH_TO_THE_WALLPAPER_IMAGE_HERE"

Important Note You'd need to make a separate task for each time you want the theme to change AND for each different theme it's going to change to using this process. Thus you'd make a task that runs every day at 1:00 to change the theme to Theme1. Another process that runs everyday that runs everyday to change the theme to Theme2, etc. The best way to do this would be to write a script but this would be an easy workaround.