LinkedIn Sourceforge

Vincent's Blog

Pleasure in the job puts perfection in the work (Aristote)

Refresh the desktop background with unsplash pictures

Posted on 2019-01-27 18:17:00 from Vincent in OpenBSD Desktop

On the unsplash website we can find lot of very nice pictures. Moreover they have a permissive license (check the unsplash license).

I share a very simple script allowing you to refresh your desktop's background at each logon, or when you want


Unsplash

For those who don't know unsplash.com allow you to use and modify freely their pictures.
If you don't know it, please check their license model

Thanks to heir API, we can download pictures base on keywords.

Basically, you can download a picture with the following URL:

https://source.unsplash.com/featured/?$QUERY

Where $QUERY will be a keyword, or a list of keywords separated by a comma.

Examples are:

https://source.unsplash.com/featured/?moon
https://source.unsplash.com/featured/?nature,water
https://source.unsplash.com/featured/?transport

An interesting feature from unsplash, is that you can specific the size of the picture you want. The file you will get, will have the size you have selected. To do that, you just have to replace "featured" by the size you want:

https://source.unsplash.com/1600x900/?moon
https://source.unsplash.com/1600x900/?nature,water
https://source.unsplash.com/1600x900/?transport

Change your desktop's background

To easily change the background, I propose to use feh

feh --bg-max $IMG_PATH

Where $IMG_PATH point to the image you want to display

Glueing all together

Putting all those elements together, you have a very simple script like this:

#!/bin/sh

QUERY=wallpaper            #comma separated words
[ "$1" ] && QUERY=$1
IMG_PATH=/tmp/unsplash.jpg
RESO=$(/usr/X11R6/bin/xrandr | awk '$2~/\*/ {print $1}')
if [ -f /usr/local/bin/feh ]
then
    /usr/bin/ftp -MV -o $IMG_PATH https://source.unsplash.com/$RESO/?$QUERY 
    /usr/local/bin/feh --bg-max $IMG_PATH
else
    echo Error !!!!
    echo You have to install feh: doas pkg_add feh
    exit 1
fi

Let's call this script "get_unsplash_bg.sh"

For info, the "ftp" command of this script, is the one of OpenBSD. If you want to use this on other OS, I think you could replace this ftp command by a curl command. But the parameters must be adapted too.

Without argument, this script will search one picture in the "wallpaper" category. But you can select other one if you want:

get_unsplash_bg.sh moon
get_unsplash_bg.sh nature,water

Integration in Openbox

If you are like me an happy user of OpenBOX, I propose you to call this script from your autostart.sh script (~/.config/openbox/autostart.sh)

Very simple script, but pleasant results



28, 28
displayed: 5209



What is the first vowel of the word Moon?