# Random Console Screensaver Module



## Michael-Sanders (Feb 6, 2013)

Simple script to load a random screensaver module. Best called from something like /etc/rc.local


```
#!/bin/sh

# only root may run the script
[ $(id -u) -ne 0 ] && exit 1

# id of current screensaver module
IDM=$(kldstat|grep -i saver|awk '{print $1}')

# list of screensaver modules excluding apm module
# if you use apm remove "\! -iname 'apm_saver.ko'"
LST=$(find /boot/kernel -type f -iname \
'*saver.ko' \! -iname 'apm_saver.ko')

# number of screensaver modules
NUM=$(echo "$LST"|wc -l)

# exit if screensaver module count < 1
[ ${NUM:=0} -gt 0 ] || exit 1

# random number from 1 to NUM
RND=$(jot -r 1 1 $NUM)

# path of random screensaver module
MOD=$(echo "$LST"|awk -v n=$RND 'NR==n {print $0; exit}')

# unload current screensaver module if appropriate
[ ${IDM:=0} -gt 0 ] && kldunload -i $IDM

# load random screensaver module
kldload $MOD

# cache last errorlevel
ERL=$?

# provide feedback
[ $ERL -eq 0 ] && echo loaded module: $MOD || echo error loading: $MOD

# exit with cached errorlevel
exit $ERL

#eof
```


----------

