Last active
August 28, 2018 16:22
-
-
Save cgrs/378b79b818febbf27cba2a6e145ea78e to your computer and use it in GitHub Desktop.
[bash] Random wallpaper from Unsplash Source
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Requisites:
curl
x11-utils
perl
libglib2.0