Monday, November 28, 2011

Change Wallpaper Script

The script below will change the wallpaper by randomly selecting a picture from a directory specified. For the script to work you will have to add it as a cron and set the interval of your choice for the wallpaper change.
 
Open your favourite editor and paste the codes below:
+++++++++++++++++++++++++
#!/bin/bash

# Directory Containing Pictures
DIR=/home/hari/Pictures
LOG=/home/hari/tapeta.log

# Command to Select a random file from directory
PIC="$(
for p in [jJ][pP][gG] [pP][nN][gG] ; do
ls $DIR/*.$p
done | shuf -n1
)"

# Command to set Background Image
if [ -z "$DBUS_SESSION_BUS_ADDRESS" ] ; then

# this is because of gconftool bug in cron
TMP=~/.dbus/session-bus
export $(grep -h DBUS_SESSION_BUS_ADDRESS= $TMP/$(ls -1t $TMP | head -n 1))
echo $DBUS_SESSION_BUS_ADDRESS >> $LOG
fi

gconftool-2 -t string -s /desktop/gnome/background/picture_filename "$PIC"
+++++++++++++++++++++++++

Note: Tested in Fedora 14 and working fine. Should work in centos and other red hat flavours.
Reffered: http://stackoverflow.com/questions/2182468/run-cronjob-as-user-to-change-desktop-background-in-ubuntu

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Affiliate Network Reviews