Tuesday, August 31, 2010

Rotating BG Using Perl

So you would think it is cool to have your Background swap out every time
you boot up or log in your machine...It can be annoying to some, especially if you
think that a wallpaper takes up to much RAM and is a waste of time (coughs)
But if you are a person that likes wallpapers so much you wouldn't mind them
changing every time you log in, then you are whom this was written for...

I wrote the following for Gnome users only...you can alter the way
you set this up real easy for Openbox/KDE

First things first
1. Obtain some wallpapers that fit your resolution of your screen exactly.
The amount of wallpapers is up to you. Make sure they are all of the .jpg extension. Place these pictures in a folder you create named 'rotate' under /home/user/Pictures/rotate...make sure you change to your 'user'...Then rename images to 1.jpg 2.jpg 3.jpg etc.


1. Disable Show Desktop in Nautilus
How to:
Alt + F2
type: gconf-editor and click Run
Navigate to Apps -> nautilus -> preferences 
Scroll down and uncheck 'show desktop'
Warning: This will not allow you to right click anymore on your desktop...Which I don't care so much about anyways.
So if this is a major issue to you then proceed no further.

2. Open a Terminal and type:
mkdir ~/scripts && cd ~/scripts
nano change_bg.pl

3. Copy and Paste this code in the terminal screen:

use strict;
use warnings;

# How many pictures you have in your rotate folder
my $num_of_pics = 10; 

# Get a random number from your total of pictures
my $pic = int(rand($num_of_pics)+1); 

# Change your background using feh to a random pic from rotate folder
print `feh --bg-center ~/Pictures/rotate/$pic.jpg`; 
      # or --bg-tile, --bg-scale, --bg-seamless
4. Change $num_of_pics to number of pictures you have in the rotate folder
     Press Ctrl + X, Y to save, and Enter

5.  Make your script executable by typing this:
chmod a+x change_bg.pl

6. Install feh with this:
sudo apt-get -y install feh

7.  Create bash script to start your script at startup by typing this:
nano startchangebg.sh

8. Copy and Paste this in startchangebg.sh, change user for your user:

cd /home/user/scripts

9. Make startchangebg.sh executable with:
chmod a+x startchangebg.sh

10.  Test your script by typing:

If your wallpaper changed, then it is working, if you are still seeing
the same wallpaper as before then you may have not disabled show desktop or you may have missed a step above.

If your wallpaper changed proceed otherwise go back through and check your steps.

11. Add Bash Script to Gnome Startup Applications:
Add new application and Browse to your /home/user/scripts/startchangebg.sh script
Finally Click Save and Close....Then Log off and back on and see if it works!
Sometimes it may choose the same background...so don't freak...the more pictures 
you have the better variety. I will say that there are ways to make a Perl script
start at boot without doing it this way...that is your choice:) I just know that
this way works too...Good luck and have fun :)
feel free to offer suggestions or ask me questions 
at naildownx at gshellz dot org

No comments:

Post a Comment