New and Improved Wallpaper Generator

I really wish I had a Mac to test this out with! I’m wondering if Mac OS X caches the wallpaper elsewhere and realizes that the image path is the same and therefore doesn’t update it.

Can you try updating your code to this and see if it works?

Code

The difference here is the addition and usage of a NOW=$(date etc) line, which makes a variable with the value of today’s date and time, which will always be unique each time the script is run. This value is then used for the filename for the wallpaper it downloads and sets. If this works, then your computer will never have an old “wallpaper.png” in its cache because it won’t ever be called the same thing.

Notice that the last two lines also need to be edited with a $NOW added, like wallpaper-$NOW.png.

#!/bin/bash

NOW=$(date +"%F_%H%M%S")

cd "$(dirname "$0")"
curl -s -A "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36" -o "wallpaper-$NOW.png" "http://wkw.natural20design.com/?k={{YOUR_API_KEY_HERE}}&d=1"
osascript -e "tell application \"System Events\" to tell every desktop to set picture to \"$(dirname "$0")/wallpaper-$NOW.png\""