You are not logged in.
I know most of you here would make this on your own if you wanted it, but for those who can't, or never bothered, here's a handy and easily editable script.
#!/bin/bash
DIR=/home/wisp/Wallpapers
FLOOR=1
RANGE=`ls -1 "$DIR"/*.jpg "$DIR"/*.png | wc | awk '// {print $1}'`
number=0
while [ 1 -eq 1 ]; do
number=$RANDOM
while [ "$number" -le $FLOOR ]; do
number=$RANDOM
done
let "number %= $RANGE" # Scales $number down within $RANGE.
COUNTER=1
for X in "$DIR"/*.jpg "$DIR"/*.png
do
if [ $number -eq $COUNTER ]; then
feh --bg-scale "$X"
fi
COUNTER=$(($COUNTER+1))
done
COUNTER=1
sleep 2m
done
There you have it!
Offline
I don't mean to steal your thunder, but it pains me to see people try and parse the output of ls. It's far simpler to generate a random file.
wp_dir=/path/to/wallpapers
WP=($wp_dir/*)
echo ${WP[(( RANDOM % ${#WP[@]} ))]}
If you need to traverse multiple directories to discover wallpapers, then just glob on multiple directories, i.e.
WP=(/path/to/foo/* /path/to/bar/*)
But please, let the shell do the work.
Last edited by falconindy (2010-08-14 02:11:07)
Offline
I like something like:
hsetroot -fill "$(find /path/to/wallpapers/ -type f | shuf -n 1)"
It presumes that all the files in your wallpaper dir are image files, but this one-liner works well for me.
Offline
Offline
Ha. This is why I put this up here: I'm a bit of a novice bash scripter, and it's nice to get these sorts of critiques. Yes, I could put the sleep time into a variable, but it's not too painful to change the sleeptime manually in a script largely written for myself. As for shuf... I had no idea that existed. Dammit! That would have been useful a little bit ago. Still, thanks for letting me know.
As for your example falcon, I don't quite understand how yours works. I guess I'm not grokking how () {} and [] work in bash.
Offline
Can you think of any way to make the transitions smooth? like in windows 7
Offline
Ha. This is why I put this up here: I'm a bit of a novice bash scripter, and it's nice to get these sorts of critiques. Yes, I could put the sleep time into a variable, but it's not too painful to change the sleeptime manually in a script largely written for myself. As for shuf... I had no idea that existed. Dammit! That would have been useful a little bit ago. Still, thanks for letting me know.
As for your example falcon, I don't quite understand how yours works. I guess I'm not grokking how () {} and [] work in bash.
Sorry, it's a bit of a mish mash of nesting in that final line. The first two lines are all the setup you need (and you may as well just use the second). This populates an array full of filenames from which to draw from. The echo line is where all the magic happens. I'll break it down...
wp_count=${#WP[@]} # size of the array -- aka the number of wallpapers
index=$(( RANDOM % wp_count)) # a random number within the bounds of the array size
echo ${WP[index]} # the wallpaper at the random index generated above
This can all be combined into the frankenstein posted above. Furthermore, it can be passed to hsetroot or feh (or whatever other utility is being used to paint the wallpaper itself) inside the while loop. Because it calls the environment variable RANDOM each time, it'll generate a new pseudo-random wallpaper on each iteration of the loop.
@hellomynameisphil: yes, you can take that shortcut, but the results of find are not meant to be piped and parsed in this way. Shell globbing is an assuredly safe way of handling any possible filename.
Offline