Description: This script will auto change background desktop by pictures from one folder after a period time that you set up. Anyway, you can add many folders contains pictures you want but their path should not has any space character. Maybe that's too late but I want to share it. Hope it usefully to you!Last changelog:
# Verion 0.1 : # Verion 0.2 : # Add function "custom options" from command
Nice script, but one thing is there is a sleep process that you can't easily turn off as a result of the timer part. And, also, if you run it manually more than once, more than one sleep process that you can't turn off occurs.
Anyway, not to condone this script, as it does work just fine, here are a couple I prefer. And they handle spaces in paths and such.
###### Random wallpaper (add whatever wallpaper directory(s) you wish after 'BACKGROUND_DIRS')
#!/usr/bin/env python
BACKGROUND_DIRS = ['/usr/share/backgrounds', '~/Pictures/Backgrounds']
EXTENSIONS = ['jpeg', 'jpg', 'bmp', 'png', 'svg']
import os, glob, random, itertools, gconf
files = list(itertools.chain(*[[os.path.join(dirpath, name)
for name in filenames]
for dirpath, dirnames, filenames in
itertools.chain(*[os.walk(os.path.expanduser(d))
for d in BACKGROUND_DIRS])]))
gconf.client_get_default().set_string(
'/desktop/gnome/background/picture_filename',
random.choice(files))
###### Automatic wallpaper switcher for Gnome
#!/bin/bash
if [ $# -ne 2 ];then
echo -n "Usage: $0 directory_name timeout_in_seconds
Leave the directory name blank for Current Directory
For you lazy pal, I assume timeout as 5 sec and Directory as current
Do you want to accept this settings? (Y/n): ";
read response
if [[ "$response" =~ ^[^yY] ]];then
exit 0
fi
fi
function set_wallpaper() {
gconftool-2 -s /desktop/gnome/background/picture_options "centered" -t string;
gconftool-2 -s /desktop/gnome/background/picture_filename "$1" -t string;
}
TIMEOUT=${2-5};
WALL_DIR=${1-`pwd`};
echo "Timeout value is: $TIMEOUT";
echo "Directory is: $WALL_DIR";
echo
if [ ! -d "$WALL_DIR" ];then
echo "The Directory Specified is invalid..";
exit 1;
fi
filelst="$(find "$WALL_DIR" -type f -name '*.jpg' -o -name '*.png')";
if [ -z "$filelst" ];then
echo "No Suitable files found in this location: $WALL_DIR";
exit 1;
fi
while true;do
filename=`echo "$filelst" | shuf -n 1`
set_wallpaper "$filename";
sleep $TIMEOUT;
done
exit
Ah. Yeah, it became quite annoying that every time I tried to kill the 'sleep' processes they just kept returning. I had to restart just to get rid of them. hehe
Ratings & Comments
3 Comments
Nice script, but one thing is there is a sleep process that you can't easily turn off as a result of the timer part. And, also, if you run it manually more than once, more than one sleep process that you can't turn off occurs. Anyway, not to condone this script, as it does work just fine, here are a couple I prefer. And they handle spaces in paths and such. ###### Random wallpaper (add whatever wallpaper directory(s) you wish after 'BACKGROUND_DIRS') #!/usr/bin/env python BACKGROUND_DIRS = ['/usr/share/backgrounds', '~/Pictures/Backgrounds'] EXTENSIONS = ['jpeg', 'jpg', 'bmp', 'png', 'svg'] import os, glob, random, itertools, gconf files = list(itertools.chain(*[[os.path.join(dirpath, name) for name in filenames] for dirpath, dirnames, filenames in itertools.chain(*[os.walk(os.path.expanduser(d)) for d in BACKGROUND_DIRS])])) gconf.client_get_default().set_string( '/desktop/gnome/background/picture_filename', random.choice(files)) ###### Automatic wallpaper switcher for Gnome #!/bin/bash if [ $# -ne 2 ];then echo -n "Usage: $0 directory_name timeout_in_seconds Leave the directory name blank for Current Directory For you lazy pal, I assume timeout as 5 sec and Directory as current Do you want to accept this settings? (Y/n): "; read response if [[ "$response" =~ ^[^yY] ]];then exit 0 fi fi function set_wallpaper() { gconftool-2 -s /desktop/gnome/background/picture_options "centered" -t string; gconftool-2 -s /desktop/gnome/background/picture_filename "$1" -t string; } TIMEOUT=${2-5}; WALL_DIR=${1-`pwd`}; echo "Timeout value is: $TIMEOUT"; echo "Directory is: $WALL_DIR"; echo if [ ! -d "$WALL_DIR" ];then echo "The Directory Specified is invalid.."; exit 1; fi filelst="$(find "$WALL_DIR" -type f -name '*.jpg' -o -name '*.png')"; if [ -z "$filelst" ];then echo "No Suitable files found in this location: $WALL_DIR"; exit 1; fi while true;do filename=`echo "$filelst" | shuf -n 1` set_wallpaper "$filename"; sleep $TIMEOUT; done exit
That's right. Perhaps I will fix it next time. Thanks.
Ah. Yeah, it became quite annoying that every time I tried to kill the 'sleep' processes they just kept returning. I had to restart just to get rid of them. hehe