Background switcher Ubuntu

Last Updated or created 2023-08-15

I was playing around with Phantomjs a headless browser.
Using this as a scraper for a ajax enabled site.

After scraping a wallpaper site, I wanted to take the big pictures and display these as background.

First sort and resize to a better size.

Below does the following:

  • Image width larger than 1800 AND
  • Image height larger than 900
  • Resize to 1920×1080 ( enlarge or reduce size )
  • Not screen filling (portrait mode) ? Than add black bars on the side.
  • Place the image in wallpaper directory

Convert script, if you resize huge images beforehand, you safe cpu resources later.
You also can place other colors or even another background instead of black.

mkdir -p wallpaper
ls * | while read ; do
info=$(identify "$REPLY" | awk '{ print $3 }' 2>/dev/null)
height=$( echo $info | cut -f2 -dx)
width=$( echo $info | cut -f1 -dx)
if [ $width -gt 1800 ] && [ $height -gt 900 ] ; then
	convert -resize 1920x1080  -gravity center  -background black -extent 1920x1080 "$REPLY" "wallpaper/$REPLY"

Set a random wallpaper as background using cron.


cd /home/henri/Pictures/
getranpic=$(ls  wallpaper/ |sort -R |tail -1)
#gsettings set org.gnome.desktop.background picture-options 'wallpaper'
#Set different modes ( enum 'none' 'wallpaper' 'centered' 'scaled' 'stretched' 'zoom' 'spanned' )
gsettings set org.gnome.desktop.background picture-uri-dark  "$(realpath wallpaper/$getranpic)"
logger "$(realpath $getranpic)" 

Cron example

* * * * * DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus /home/henri/bin/setrandom
Spread the love

Leave a Reply

Your email address will not be published. Required fields are marked *