You are not logged in.

#1 2008-07-07 20:56:58

pseudonomous
Member
Registered: 2008-04-23
Posts: 349

bash script: Rotate your wallpaper and SLiM theme at the same time

EDIT;

I've decided I should really thank Cerebral for his help with writing this script; this thank you should have been here from the get go.

After writing:

#!/usr/bin

echo "Hello World!"

I wrote a script to rotate my fluxbox background and SLiM theme at the same time, so I could have a contiuously changing background and still have a smooth transition from SLiM to fluxbox.  (It just looks so much cooler when both have matching backgrounds).  By the time you finish reading it, and configuring your box so it will work, you will probably have decided you could have writtin your own, better script to do the same thing.  But, on the off chance anybody finds use for it, here it is:

(this should be obvious, but: don't run this script without at least reading the comments)

#!/bin/bash
#this is a script to rotate a number of backgrounds
#to be shared by the fluxbox desktop and SLiM login manager.
#it is the first meaningful script I've written.  It may be
#freely distributed and used with the understanding that you are
#using it at your own risk. 
#
#Before running this script you need to check that your SLiM
#themes are installed to the path /usr/share/slim/themes, which
#is the defulat path for installation in Arch.  Here are some
#other things you need to set up:
#
#1. create (if you don't have it) the directory /usr/share/wallpapers
#
#2. create a wallpaper in /usr/share/wallpapers called 'dummy' by copying
#you current wallpaper to that filename
#
#3. set your window manager to display the wallpaper 'dummy', this works fine
#using a style overlay in fluxbox, I haven't tested it with any other window
#manager, but I don't see why this would cause a problem.
#
#4. create a directory /usr/share/slim/themes/current, you can copy one of
#your slim themes into that directory if you want.  (this will prevent you
#from seeing some error messages the first time you run the script)
#
#5. define the names of the themes you want to rotate, in order for this
#script to work, you must name them "themeNUMBER", where NUMBER is replaced
#by an integer.   Your themes must be numbered consecutively, start with 1
# that is:
# 
#theme1 , theme2, theme3, etc. , theme305
#
#If you don't number consecutively, this script will not run properly.  You
#must also define the total number of themes as "rotate_number"
#
#6. Check if the script runs, if it does, you should change /etc/slim.conf to
#use the theme "current"
#
#7. This theme will now rotate your SLiM theme and wallpaper in such a way as
#to make them match each other.  Note that SLiM will not let you change themes
#"on the fly", (as of July 6, 2008), so changes will not be apparent unless you
#restart SLiM.  I run the script before I run slim in my etc/rc.local local
#script, so each time I reboot I get different wallpaper / login background.
#
#Fred Drueck 2008

#Define here all themes to be rotated and the total number of
#themes to rotate:

rotate_number=9

theme1=/usr/share/slim/themes/default
theme2=/usr/share/slim/themes/lake
theme3=/usr/share/slim/themes/lunar
theme4=/usr/share/slim/themes/flower2
theme5=/usr/share/slim/themes/the-light
theme6=/usr/share/slim/themes/mindlock
theme7=/usr/share/slim/themes/parallel-dimensions
theme8=/usr/share/slim/themes/wave
theme9=/usr/share/slim/themes/fingerprint

#check you are running this script as super-user:

if [ $(id -u) != "0" ]; then
    echo "You must be the superuser to run this script" >&2
    exit 1
fi

echo "rotating themes"


#figure out which theme is currently set, then name it as the variable
#"last theme number", otherwise set last theme number as 0

if [ -f /usr/share/slim/themes/current/current_theme_number ]
then
   echo "checking current theme"
   cd /usr/share/slim/themes/current/
   eval last_theme_number=$(cat /usr/share/slim/themes/current/current_theme_number) 
   echo $last_theme_number
else
   echo "no theme is currently set, using theme 1"
   last_theme_number=0
   echo $1 > /usr/share/slim/themes/current/current_theme_number
fi

#set the new theme number

eval new_theme_number=$(($(($last_theme_number % $rotate_number))+1)) 

#select the new theme

placeholder=theme
eval new_theme=\$$placeholder$new_theme_number
echo $new_theme

#now clean out the "current" theme where I keep the current
#theme for slim
       
rm /usr/share/slim/themes/current/background*
rm /usr/share/slim/themes/current/panel*
rm /usr/share/slim/themes/current/slim.theme

#the wildcards are there since the themes use jpg and png files

cp $new_theme/background* /usr/share/slim/themes/current
cp $new_theme/panel* /usr/share/slim/themes/current
cp $new_theme/slim.theme /usr/share/slim/themes/current

#increase the theme number, but first clear the old file

rm /usr/share/slim/themes/current/current_theme_number
echo $new_theme_number > /usr/share/slim/themes/current/current_theme_number

#copy over the dummy wallpaper in "/usr/share/wallpapers" (with the theme 
#background file

cp $new_theme/background* /usr/share/wallpapers/dummy

exit 0

Last edited by pseudonomous (2008-07-07 21:59:42)

Offline

Board footer

Powered by FluxBB