Saturday 3 September 2011

Changing GNOME 3 wallpaper

I have been using fedora with gnome 3 for many months.Even though GNOME 3 is a great release,its has some rough edges too.In this example I will explain how to change the wallpaper in regular interval(say 1 minute interval).Here I am using perl script to accomplish my goal.You can also use python to do the same.Following are the steps
  1. Create a directory(ex: /home/senan/wallpaper) and copy all the images to it or you can use the default wallpaper directory
  2. we will store the image names in array
  3. Then we will pick an image randomly and set it as wallpaper using gsettings every 10 seconds
use the following perl script to do the above things

#!/usr/bin/perl -w
#
# Author      : Prabhendu V Senan
# Description : This is a perl script for changing the Gnome wallpaper in a specified time interval
# File Name   : change_wall.pl
#

# Directory containing the wallpaper images
$wallDir = '/home/senan/wallpaper';

# Wallpaper change interval time

$interval = 10;

# First check whether the directory containing images exists or not

unless(-d $wallDir)
{
  print "There is no such $wallDir directory \n";
  exit();
}

# Parse the directory,get all the image filenames and fill it into an array

@images = `find $wallDir -type f | grep [jJ]*[pP][nN]*[eE]*[gG]`;

chomp(@images);

#if the directory has no images,Exit()

if(@images == 0)
{
  print "No Images found in $wallDir \n";
  exit();
}

my $nowShowin;

while(1)
{
   $nowShowing = $images[rand(@images)];
  `gsettings set org.gnome.desktop.background picture-uri "file:///$nowShowing"`;
   sleep($interval);
}

To run the script: Copy and paste it into your favourite text editor.
  1.  Save the file(ex:wallChange.pl
  2.  Make it executable(ex: chmod +x wallChange.pl)
  3.  CD to script dir and run the script :-)
  4.  To run the script during start up:Open gnome-session-properties->Add->Browse the script and add :-) 
  5. Restart your computer



2 comments:

  1. Any reason the path isnt ~/wallpaper instaed of /home/snot/wallpaper ?

    ReplyDelete
  2. No special reason. There is a wallpaper slideshow app for gnome 3. You can take a look at the following link if you are interested

    http://www.omgubuntu.co.uk/2011/06/wallpaper-slideshow-app-for-gnome-3/

    ReplyDelete