Howto time-controlled change the wallpaper and theme in Ubuntu 14.04

In this article I describe how to set up a time-controlled, automatic change of the wallpaper and the theme of Unity (GTK 3). I like to have a dark theme and wallpaper at night:

My Ubuntu desktop at night.
My Ubuntu desktop at night.

By day I prefer a bright theme and wallpaper:

My Ubuntu desktop by day.
My Ubuntu desktop by day.

So my solution works at follows. I use the following script that performs the change:

First it is necessary to determine the address of the dbus session to make gsettings working. Usually you use it in a gnome-shell where this environment variable exists. This is not the case if you use this script with cron. We then determine the current hour and distinguish between day and night by comparing it with 8 and 18. So it is day after 8 (am) and before 19 (7 pm). The path to the wallpapers must be changed to your desired pictures. I use the themes OMG and Gnome-Cupertino. You can find themes and instructions how to install them at http://gnome-look.org/index.php?xcontentmode=167. Save this script for example under “set theme” and use the following command to make it executable:

Now we have to start the script when it is time for a change. A handy tool is gnome-schedule. You can install it with the command:

Here is a screenshot of gnome-schedule.

Screenshot of Gnome-Schedule, a tool to schedule tasks.
Screenshot of Gnome-Schedule, a tool to schedule tasks.

Click new for a new task. Enter a descriptive “Description“. “Command” is the path to our new script. Select that it is an X application. Since we want to start it once when the day starts, select “Advanced” and enter the time 8h and 5m, so it is called 5 minutes after the day starts. As you can see in the screenshot, a second entry is necessary to change theme and wallpaper to night. It is basically the same entry but with a different time.

Since we also want to right theme and wallpaper when our computer is not running at 8:05 and 19:05, we have to use another application called “Startup Applications”. Just add a new entry pointing to that script.