Created
February 27, 2017 12:29
-
-
Save ilkka/e3739c1c98081450c49c2a9ddf318c54 to your computer and use it in GitHub Desktop.
Get random unsplash wallpaper for mac in your display's resolution
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 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