sexta-feira, 29 de janeiro de 2010

Shell Script that randomly change image on Linux Desktop

Use this script to randomly display a different image every x seconds. All the images on a given directory are chosen. An image will be chosen at random and displayed each time by the script.

Usage:
You pass to program the images directory that you wants and the interval time
$ ./change_wallpaper.sh "/home/USER_DIRECTORY/Pictures/" "60"

#código
#!/bin/bash
#Program made by
##António L. R. Mendes
function setPaper(){
    declare -a ARRAY
    PATH_IMG=$1
    TIME=$2
    ARRAY=$(ls $PATH_IMG | grep [jpg][png] | sort -R)
       
    for i in $ARRAY; do
        gconftool-2 -t str -s /desktop/gnome/background/picture_filename "$PATH_IMG/$i"
        sleep $TIME
    done
   
    setPaper $PATH_IMG $TIME

}



#we can config:
# $1 - path to the images
# $2 - time to change
PATH_IMG=$1
TIME=$2
if [ ! -d "$PATH_IMG" ]; then
    echo "The directory $PATH_IMG is not a valid directory."
    exit
fi

if [ ! $TIME -gt 0 ]; then
    echo "The time introduced is not valid so the default value is 60 sec."
    $TIME=60
fi


echo "Program will change images in $PATH_IMG every $TIME seconds."
setPaper $PATH_IMG $TIME


Sem comentários:

Enviar um comentário