I had a problem. I had a lot of nice pictures I thought would be good for a wallpaper but I was too lazy to change it manually with something else regularly. This is because I don't use a "mainstream" window manager with some utility that would do that automatically. But after searching a bit, I rejoiced. Without further ado, code:
#!/bin/sh
case hostname
in
tyneth)
width=1400
height=1050
;;
)
width=1280
height=1024
;;
esac
tmppath=/tmp/my-wallpaper-"$LOGNAME"
if [ ! -d "$tmppath" ]
then
mkdir "$tmppath"
else
rm "$tmppath"/
fi
filename=find $HOME/perso/Wallpapers/ -type f | shuf -n 1
fileonly=basename "$filename"
radix=echo "$fileonly" | sed -e 's/\\.[a-zA-Z]\\+$//'
output="$tmppath"/"$radix".png
nice convert \
\( \( "$filename" -gravity Center -crop "80x80%%+0+0" \
-resize "$width"x +repage -crop "$width"x"$height"+0+0 \
-resize x"$height" +repage -crop "$width"x"$height"+0+0 \
-blur 0x40 +repage \) \
\( "$filename" -resize "$width"x"$height" -matte \
-background black -shadow 100x16 \) \
-gravity Center -composite \) \
\( "$filename" -resize "$width"x"$height" \) \
-composite -flatten +repage -strip -quality 80 "$output"
display -window root "$output"
This scripts checks the host to get an idea of what resolution might the active one, sets up a temporary directory in /tmp, randomly shuffles through a directory where there are only pictures, converts a chosen picture to the desired resolution with nice blurring effects if the ratio is different and finally displays it. The code for converting is not done by me, by the way, but I can't find the original author.
Then I put the following in my crontab (assuming the script is called my-wallpaper.sh and put in the mentioned directory:
0 env DISPLAY=:0.0 $HOME/usr/bin/my-wallpaper.sh
Then I have a wallpaper that changes every hour. Bonus point: as the basename of the file is kept in /tmp, if I decide I do not like the wallpaper I can look for it in my pictures directory and remove it. Hence with time my pictures directory will only contain pictures that I deem worthy of my monitor's background.
Commentaire n°1
- username: Matthieu Weber
- url: http://www.mit.jyu.fi/mweber/blog/
- date: 2008-09-23T07:49:17
"xdpyinfo |grep dimensions" gives you the dimensions of the current DISPLAY. With a little help from cut or sed you can easily get those values automatically instead of hardcoding them.
Commentaire n°2
- username: Samuel
- url: http://hivernal.org
- date: 2008-09-23T11:04:55
This is actually the problem: with xinerama xdpyinfo displays the resulting resolutions if I have 2 monitors, while "display" displays on each background. Hence the hostname detection. ATM I'm too lazy to look for a solution to this problem, though.