2018-04-03 15:31:43 +02:00
|
|
|
#!/bin/bash
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
#Unsplash API access key: https://unsplash.com/oauth/applications
|
2018-04-03 15:59:29 +02:00
|
|
|
: ${ACCESS_KEY:=""}
|
2018-04-03 15:31:43 +02:00
|
|
|
|
|
|
|
#Comma separated collection ids: https://unsplash.com/collections
|
2018-04-03 15:59:29 +02:00
|
|
|
: ${COLLECTIONS:=""}
|
2018-04-03 15:31:43 +02:00
|
|
|
|
2018-04-03 15:47:18 +02:00
|
|
|
#Name of the jpg file to use
|
2018-04-03 15:59:29 +02:00
|
|
|
: ${WALLPAPER_LOCATION:=~/Images/wallpaper.jpg}
|
2018-04-03 15:47:18 +02:00
|
|
|
|
|
|
|
#Name of the info (txt) file
|
2018-04-03 15:59:29 +02:00
|
|
|
: ${INFO_LOCATION:=~/Images/wallpaper.txt}
|
2018-04-03 15:47:18 +02:00
|
|
|
|
2018-04-03 15:31:43 +02:00
|
|
|
#Get new random info
|
|
|
|
photo=$(curl -sf -H "Accept-Version: v1" -H "Authorization: Client-ID ${ACCESS_KEY}" "https://api.unsplash.com/photos/random?featured&orientation=landscape&collections=${COLLECTIONS}&random=${RANDOM}")
|
|
|
|
photo_url=$(echo ${photo} | jq -r ".urls.full")
|
|
|
|
photo_location=$(echo ${photo} | jq -r ".location.title")
|
|
|
|
photo_username=$(echo ${photo} | jq -r ".user.name")
|
|
|
|
|
|
|
|
#Download it
|
2018-04-03 15:47:18 +02:00
|
|
|
curl -Lsf -o ${WALLPAPER_LOCATION} ${photo_url}
|
2018-04-03 15:31:43 +02:00
|
|
|
|
|
|
|
#Set as wallpaper
|
2018-04-03 15:47:18 +02:00
|
|
|
nitrogen --save --set-zoom ${WALLPAPER_LOCATION}
|
2018-04-03 15:31:43 +02:00
|
|
|
|
|
|
|
#Put wallpaper info into text file (eg for Conky)
|
2018-07-11 15:23:00 +02:00
|
|
|
if [[ "${photo_location}" == null ]] ; then
|
|
|
|
echo "Photo by ${photo_username}" > ${INFO_LOCATION}
|
|
|
|
else
|
|
|
|
echo "Taken in ${photo_location} by ${photo_username}" > ${INFO_LOCATION}
|
|
|
|
fi
|
2018-04-03 15:31:43 +02:00
|
|
|
|
|
|
|
# vim:set ts=2 sw=2 et:
|