Monday, December 28

Backgrounds in Gnome 2.28

One of the neat things about Gnome 2.28 is the background slideshow.  I know, it's cheesy, but it's the first time I can remember something like this being baked into a display manager.

Of course, one of the things you'll want to do is create these slideshows, but the process can be painstakingly tedious.  Reasons 1-34786 are, you have to edit XML.  It's ugly, it's verbose, but it's pretty good for describing data... and making you want to throw up if you have to edit it.

However, due to the awesomeness of bash shell, I  have created a small shell script that will build this xml file from the contents of a directory.  The usage is simple, and easy to extend for your own use.  Currently it accepts jpg and png files, indicated by the optional arguments j and p.  It also accepts one argument for the directory where your images are located.   The default values are jpg and the current directory.

Here is the script.


#!/bin/sh
SHOW_DURATION=100
TRANSITION_DURATION=5.0

format=jpg
source_dir=$(pwd)

while getopts jph fmt
do
  case $fmt in
  j) format=jpg;;
  p) format=png;;
  h) echo "Usage: $0 [jph] [image directory]";exit 0;
  esac
done

shift $(($OPTIND - 1))
if [ -n "$*" ]; then
  source_dir=$*
fi


echo "" > background.xml
echo "20090804000000" >> background.xml
for file in $( ls ${source_dir}/*.${format} ); do
   if [ -n "${first}" ]; then
        echo "${file}
" >> background.xml
   else
        first=$file
   fi
   echo "${SHOW_DURATION}${file}" >> background.xml
   echo "${TRANSITION_DURATION}${file}" >> background.xml
done
echo "${first}
" >> background.xml
echo "" >> background.xml

No comments: