Skip to content

Instantly share code, notes, and snippets.

@ilkka
Created February 27, 2017 12:29
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 ilkka/e3739c1c98081450c49c2a9ddf318c54 to your computer and use it in GitHub Desktop.
Save ilkka/e3739c1c98081450c49c2a9ddf318c54 to your computer and use it in GitHub Desktop.
Get random unsplash wallpaper for mac in your display's resolution
#!/usr/bin/env fish
if not command -s system_profiler >/dev/null
echo "system_profiler not found" ^&2
exit 1
else if not command -s osascript >/dev/null
echo "osascript not found" ^&2
exit 1
else if not command -s xmlstarlet >/dev/null
echo "xmlstarlet not found" ^&2
exit 1
else if not command -s curl >/dev/null
echo "curl not found" ^&2
exit 1
else if not command -s sed >/dev/null
echo "sed not found" ^&2
exit 1
end
set resolution (system_profiler -xml SPDisplaysDataType|xmlstarlet sel -t -v "//array/dict/key[. = '_spdisplays_pixels']/following-sibling::string[1]" ^/dev/null)
set tempdir (mktemp -d)
set tempfile $tempdir/bg.jpg
curl -s "https://unsplash.it/"(echo $resolution|sed 's% x %/%')"/?random" >$tempfile
osascript -e 'tell application "Finder" to set desktop picture to POSIX file "'$tempfile'"'
rm -r $tempdir
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment