Skip to content

Instantly share code, notes, and snippets.

@axi
Last active July 24, 2024 16:06
Show Gist options
  • Save axi/441881d828d51cb164128c2aa6873e70 to your computer and use it in GitHub Desktop.
Save axi/441881d828d51cb164128c2aa6873e70 to your computer and use it in GitHub Desktop.
Set a wallpaper from St-malo France webcam
#!/bin/bash
#
# Add a cron job to run this script every 15 minutes.
# crontab -e
# 5,35 * * * * /home/YOUR_USER_NAME/Documents/unsplash.sh
#
USER=$(whoami)
# to find api_key, explore requests on webcam display page (for ex https://api.skaping.com//media/search and look for POST api_key)
# Saint-malo hotel de ville
wall_1[0]='CNGkm-ycf3x-YLDgn-c3uyp' # api_key = webcam id
wall_1[1]='4500+0'
#size='3840x2160' # 16/9
#wall_1[1]='4500+0'
size='5160x2160' # 21/9
wall_1[1]='3840+0'
wall=("${wall_1[@]}")
# Delete cached wallpaper.
rm -f /home/$USER/.cache/wallpaper/*
# Download image.
curl -L -o /tmp/wallpaper-tmp.jpg "https://api.skaping.com/media/getLatest?format=jpg&api_key=${wall[0]}"
cp /tmp/wallpaper-tmp.jpg /tmp/wallpaper-tmplala.jpg
# crop 12231 x 2160 => size (16/9 or 21/9)
mogrify -crop ${size}+${wall[1]} /tmp/wallpaper-tmp.jpg
convert -font helvetica -fill black -pointsize 40 -gravity SouthEast -draw "text 30,100 '$(TZ="Europe/Paris" date +"%H:%M")'" /tmp/wallpaper-tmp.jpg /tmp/wallpaper-tmp.jpg
mv /tmp/wallpaper-tmp.jpg /home/$USER/Images/wallpaper.jpg
# Set new wallpaper ## 'none', 'wallpaper', 'centered', 'scaled', 'stretched', 'zoom', 'spanned'
gsettings set org.gnome.desktop.background picture-options "scaled"
gsettings set org.gnome.desktop.background picture-uri "file:///home/$USER/Images/wallpaper.jpg"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment