you're reading...

Automatically changing wallpaper relatively to daytime in Ubuntu

Fedora 8 introduced a nice feature which is automatically changing wallpaper relatively to daytime. Here’s how to have this cool feature in Ubuntu (and any other linux distribution) !
Select four wallpapers, one to be displayed at sunrise, the second during the day, third at sunset and the last at night.
Then, in a terminal, create a bash script as follows :

gedit .change.sh

You’ll get the newly created .change.sh file opened in a text editor.
Copy the following text in the file (Change the PATH-TO-**-PICTURE with the appropriate path) :

HOUR=$(date +%H)
case “$HOUR” in
gconftool -t string -s /desktop/gnome/background/picture_filename PATH-TO-SUNRISE-PICTURE
gconftool -t string -s /desktop/gnome/background/picture_filename PATH-TO-DAY-PICTURE
16|17|18 )
gconftool -t string -s /desktop/gnome/background/picture_filename PATH-TO-SUNSET-PICTURE
gconftool -t string -s /desktop/gnome/background/picture_filename PATH-TO-NIGHT-PICTURE

As you can tell, this script sets the appropriate picture depending on the system’s current hour.
Now we’ll create a cron job, which is a linux way to automatically run tasks.

gedit .change.cron

This will open the text editor to edit our cron job.
Copy the following in the text editor (Replace YOUR-HOME-FOLDER by your home folder’s absolute path):

* 4,8,16,19 * * * YOUR-HOME-FOLDER/.change.sh

As you see, the cron task will lauch our previously created script at 4am, 8am, 4pm and 7pm to set the adequate wallpaper.
(Of course, you can change the hours at your convenience).
Now, let’s add these tasks to our gnome session so that they are automatically launched every time we login.
Open the System>Preferences>Sessions menu.
* Click the Add Button
Name: Changing Wallpaper Cron
Command: crontab PATH-TO-YOUR-HOME-FOLDER/.change.cron
Click Ok
Now the job of automatically changing wallpaper is set as an automated job every time we login.
We also have to add the script at session startup so that the correct wallpaper is initialized when we login. (This means, that if you login at e.g. 5:30pm, you’ll have the right wallpaper for that time). To do that,
* Click again the Add Button
Name: Initializing Wallpaper
Command: PATH-TO-YOUR-HOME-FOLDER/.change.sh
Click Ok
Here you are ! Your desktop wallpaper is living and reflecting the daytime!

About abdessemed mohamed amine



2 thoughts on “Automatically changing wallpaper relatively to daytime in Ubuntu

  1. mmmm

    Posted by mahmoud | March 13, 2009, 13:20
  2. Is there a way to do it on Mac?

    Posted by andy | June 26, 2010, 23:52

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


March 2009
« Feb   Apr »


Error: Twitter did not respond. Please wait a few minutes and refresh this page.

  • 366,864 Visit !
%d bloggers like this: