Hemanth's Scribes

web

Random Images From Xkcd as Wallpaper

Author Photo

Hemanth HM

Thumbnail

Random Images From Xkcd as Wallpaper

Afterhowto use real-time earth wallpaper i tired to make some random xkcd images as my wallpaper. The below is a simple script which one can use to get random images from xkcd as desktop wallpapers at a time interval of 3600 seconds Steps: 1. mkdir -p ~/.xkcd 2. Place the code in this dir, call it xkcds.bash. 3. Setup a cron job or put the code in rc, as : 0 * * * * ~/.xkcd/xkcds.bash [or] cp ~/xkcd/xkcds.bash /etc/init.d/ && update-rc.d xkcds.bash defaults

#!/bin/bash

while [ 1 ]; do

# Remove old images if any!
rm -rf *.png

#Get the random image
wget $(curl -sL "http://dynamic.xkcd.com/random/comic/" \
    | grep "http://imgs.xkcd.com/comics/"\
    | awk -Fsrc=\" '{print $2}'\
    |awk -F\" '{print $1}') -O xkcd-$(date +'%S').png

#Set the image based on the desktop session

[[ $DESKTOP_SESSION == "gnome"]] && gconftool-2 --type string --set \
/desktop/gnome/background/picture_filename ~/.xkcd/xkcd*.png

[[ $DESKTOP_SESSION == "kde" ]] &&  dcop kdesktop KBackgroundIface \
setWallpaper xkcd*.png 1

#Have a nap
sleep 3600

done
#javascript#linux
Author Photo

About Hemanth HM

Hemanth HM is a Sr. Machine Learning Manager at PayPal, Google Developer Expert, TC39 delegate, FOSS advocate, and community leader with a passion for programming, AI, and open-source contributions.