#!/bin/bash # # purpose : use random image from gnome art (art.gnome.org) as a wallpaper # author : kyanh # license : gpl (version 2) # version : $Id: gnome-art 3645 2009-05-30 22:30:21Z pi $ # requires: lynx, feh, awk, bash # homge : http://viettug.org/projects/show/fs (please search there) # custom : # * _SET_BACKGROUND : a program to set wallpaper using image url # * _RESOLUTION : environment to provide resoultion match (default: 1024x) # option : # * --update : update the cache file $HOME/.gnome-art.log # # notes : # This program will use a cache file ($_tempfile, see below) to save # the list of image URLs. You will use any program to get a random # url from this list and set the desktop background using that url. # To update the cache file, use --update option. The program also # update the cache automatically if it found nothing in cache. # You'll need a internet connection and wait for a while if you # want to update stuff. *DO NOT* modify the cache file manually # as your changes may be overriden. # _SET_BACKGROUND="feh --bg-center" _resolution=${_RESOLUTION:-1024x} _src=http://ftp.gnome.org/pub/GNOME/teams/art.gnome.org/backgrounds/ _tempfile="$HOME/.gnome-art.log" _msg() { echo -e ":: $*" return 1 } _ignore_spaces() { tr -d '[ \t]' } _update() { _msg "updating the list of image (please wait)" lynx -dump $_src \ | grep http:// \ | grep $_resolution \ | awk '{print $2}' \ | sort -u \ > $_tempfile _msg "(done)" } touch $_tempfile || _msg "cannot create temporary file $_tempfile. exit 1" || exit 1 _image_count="$(wc -l < $_tempfile | _ignore_spaces)" _msg "found $_image_count image(s) in cache file $_tempfile (precheck)" if test "x$1" == "x--update"; then _update elif test $_image_count -eq 0; then _update fi _image_count=$(wc -l < $_tempfile | _ignore_spaces) _msg "found $_image_count image(s) in cache file $_tempfile" if test $_image_count -gt 0; then _image_random=$((RANDOM % _image_count + 1)) _image_url=$(cat $_tempfile | head -"$_image_random" | tail -1) _msg "going to use the random image $_image_random" _msg "image url = $_image_url" $_SET_BACKGROUND $_image_url fi