Skip to content

Instantly share code, notes, and snippets.

@cgrs
Last active August 28, 2018 16:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cgrs/378b79b818febbf27cba2a6e145ea78e to your computer and use it in GitHub Desktop.
Save cgrs/378b79b818febbf27cba2a6e145ea78e to your computer and use it in GitHub Desktop.
[bash] Random wallpaper from Unsplash Source
#!/usr/bin/env bash
# Random wallpaper from Unsplash Source
function setWallpaper {
local file=$1
if test -z $file; then
echo "Error: no file specified"
return 1
elif test -e $file; then
local uri=$(perl -MURI::file -e "print URI::file->new('${file}')")
gsettings set org.gnome.desktop.background picture-uri $uri
echo "Wallpaper set"
return 0
else
echo "Error: ${file} does not exist"
return 1
fi
}
function randomPaper {
local file="$(xdg-user-dir PICTURES)/wallpaper-$(date +%Y-%m-%d).jpg"
if [[ ! -e $file || $1 = "-f" ]]; then
local resolution=$(xdpyinfo | awk '/dimensions/ {print $2}')
echo "Fetching wallpaper..."
curl --progress-bar -Lo $file "https://source.unsplash.com/random/${resolution}"
setWallpaper $file
else
echo "Wallpaper already exists"
return 1
fi
}
randomPaper
@cgrs
Copy link
Author

cgrs commented Aug 28, 2018

Requisites:

  • curl
  • x11-utils
  • perl
  • libglib2.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment