Saturday, November 19, 2005

Gnome-Terminal Background Randomizer

Here's a nice script you can use in cron or elsewhere to change your
gnome-terminal background.

#!/bin/sh
#
# Gnome-Terminal Random Background
# -----------------------------------
# Greg Harris
# 6.13.05
#
# Run this script every time you want to update
# your terminals background image.
#

# This is really all you need to setup. Point it to a directory
# with all of your background images.
BGPATH=/home/angrylogic/Documents/Backgrounds
FILTERS="*.jpg *.JPG *.png *.PNG *.tiff *.TIFF *.gif *.GIF"
PROFILE=Default

# Set counters and lists to nothing
NUM=0
TOTAL_PICS=0
PIC_LIST=

# Generate the list of pictures depending on wither or not
# we are doing extension filtering. If your directory has
# non-image files, you want to use filtering.
if [ -n FILTERS ]
then
PIC_LIST=`ls -1 $BGPATH`
else
for FITLER in FILTERS
do
PIC_LIST=$PIC_LIST `ls -1 $BGPATH/$FILTER`
done
fi

# Calculate the total amount of pictures, and then choose
# a random picture from the total amount of pictures
let TOTAL_PICS=`echo $PIC_LIST | wc -w`
let RAND_PIC=$RANDOM%$TOTAL_PICS

# FIXME:
# If anyone knows a better way of extracting a certain element
# from a list in bash please email me. I couldn't find anything in
# my poking around and I couldn't get the cut utility to take
# space as a delimiter
for PICTURE in $PIC_LIST
do
let NUM=$NUM+1
# Loop until we find our lucky picture in the list, and set
# that up as the background picture.
if [ $NUM -eq $RAND_PIC ]
then
# This updates the gconf key pointing to your profile
# and sets up your background image accordingly
gconftool-2 --type string --set
/apps/gnome-terminal/profiles/$P ROFILE/background_image $BGPATH/$PICTURE
fi
done