Skip to content

Instantly share code, notes, and snippets.

@navidanindya
Last active March 29, 2021 19:02
Show Gist options
  • Save navidanindya/4d883528f7ed3b7f37b1c7760e922c5d to your computer and use it in GitHub Desktop.
Save navidanindya/4d883528f7ed3b7f37b1c7760e922c5d to your computer and use it in GitHub Desktop.
Auto Change Wallpaper from Unplash collection.

Autochange Wallpaper from Unsplash

This simple shell script runs every hour and takes an image from Unplash.com and sets it as a wallpaper. You can choose whatever wallpaper you want by changing the URL in wget of the shell script.

Go to source.unplash.com to know more about the Unplash API.

Installation

  • Place this script in your /bin directory.
  • Open your terminal and make it executable with sudo chmod +x /bin/unsplash.sh
  • Run it using ./unsplash.sh
  • This will add the cronjob automatically and set your wallpaper.

NB: If you change your script name from unsplash.sh to anything.sh, rename the file name in the code.

#/bin/bash
echo "Getting wallpaper from collection."
wget -O /tmp/wallpaper.jpg https://source.unsplash.com/collection/1166960/1920x1080
gsettings set org.gnome.desktop.background picture-uri file:///tmp/wallpaper.jpg
echo "Wallpaper set."
# Now set cronjob of an hour
echo "Setting cron to change wallpaper every hour"
if crontab -l | grep "unsplash.sh"; then
echo "Cron exists. Continue to run normally."
else
(crontab -l ; echo "0 * * * * /bin/unsplash.sh") | crontab -
echo "Cron set. Wallpaper will change every hour now."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment