Skip to content

Instantly share code, notes, and snippets.

@jessestricker
Last active August 3, 2022 16:38
Show Gist options
  • Save jessestricker/32d7940dd520edf54c3c330a86a3b556 to your computer and use it in GitHub Desktop.
Save jessestricker/32d7940dd520edf54c3c330a86a3b556 to your computer and use it in GitHub Desktop.
Get a Random Wallpaper from Unsplash!
#! /usr/bin/env bash
set -e -u -o pipefail
# set options
COLLECTION_ID='317099' # Unsplash Editorial (aka Picture of the Day)
# set constants
IMG_RESOLUTION=$(xrandr --current | grep '\*' | awk '{print $1}' | sort | tail -n 1)
IMG_REMOTE_URI="https://source.unsplash.com/collection/${COLLECTION_ID}/${IMG_RESOLUTION}"
IMG_LOCAL_DIR=$(realpath --canonicalize-missing "${HOME}/Pictures/Wallpapers")
IMG_LOCAL_PATH="${IMG_LOCAL_DIR}/splash.jpg"
IMG_LOCAL_URI="file://${IMG_LOCAL_PATH}"
GSETTINGS_SCHEMA='org.gnome.desktop.background'
GSETTINGS_KEYS=('picture-uri' 'picture-uri-dark')
# download
echo "downloading..."
mkdir --parents "$IMG_LOCAL_DIR"
curl --location --output "$IMG_LOCAL_PATH" --progress-bar "$IMG_REMOTE_URI"
# set as wallpaper
echo "applying..."
for key in "${GSETTINGS_KEYS[@]}"; do
gsettings set "$GSETTINGS_SCHEMA" "$key" "$IMG_LOCAL_URI"
done
echo "done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment