Skip to content

Bing wallpaper on a Mac

While this version of the script should still work, I’ve uploaded a new version of the script based on Python, using a different image source here: Bing wallpaper on a Mac 2.0

I use Bing Desktop on my Windows machine at the office exclusively for the wallpaper images. At home I have a Mac and I wanted an easy way to get the same wallpapers on my Mac. After some online searching I couldn’t find a solution that I was pleased with, so I wrote my own (below).


#!/usr/bin/env bash

# create our directory tree
mkdir -p ~/Pictures/Bing/Archive

# change to our destination directory
cd ~/Pictures/Bing

# today's image
URL=$(curl -s http://feeds.feedburner.com/bingimages | grep url | sed -e "s/.*url=\"\([^\"]*\).*/\1/" | head -1)
URLSIG=$(/sbin/md5 -q -s ${URL})
TODAY="$(date +%Y-%m-%d)_${URLSIG}.jpg"

# exit if we already have today's image
if [[ $(find . -type f -name "*${URLSIG}*") ]];
then
    exit 0
fi

# archive old images
mv ./*.jpg Archive/

# download latest image
curl ${URL} -s -o ${TODAY}

# the next time OS X changes the wallpaper it should find the the new file and update the wallpaper
# assumes OS X is configured to rotate the wallpaper from ~/Pictures/Bing at some interval
# i run this script on the 59th minute of every hour and configured OS X to change the wallpaper every hour

The script only downloads the latest image in the Bing Images feed if a file isn’t found with the same URL signature (MD5 hash) in the destination directory tree. If the script decides it needs to download a new file, it first archives the current file and then downloads the new file. The archive step can be commented out if you would like to keep prior wallpapers in the rotation. My preference is to always use the latest wallpaper.

To run the script save it anywhere, like your home directory, and make it executable:

chmod +x bing_wallpaper.sh

Then you can set up a crontab or run it manually. I set up a crontab for the 59th minute of each hour to run the script

59 * * * * ~/bing_wallpaper.sh

Finally, I configured OS X to change the wallpaper every hour from the destination directory.

I published this script to GitHub here.

7 Comments

  1. cf wrote:

    great! thank you!

    Tuesday, December 9, 2014 at 4:30 am | Permalink
  2. Dave wrote:

    Hi MG,

    Thank you for this great script. I’ve managed to get it working from the command line and can retrieve the file that.

    However, cron is complaining of an error in the script that doesn’t appear when running from the command line.

    Cron is saying:

    /Users/xxxxxx/bing_wallpaper.sh: line 11: md5: command not found

    which refers to the line:

    URLSIG=$(md5 -q -s ${URL})

    I’m afraid I’m an OS X noob, so am unsure how to tackle this one.

    Any ideas how to tackle this?

    I’m on OS X 10.10

    Saturday, January 17, 2015 at 2:43 pm | Permalink
  3. MG wrote:

    When that happens you need to fully qualify the executable, so it would become: URLSIG=$(/sbin/md5 -q -s ${URL}). There’s a new Python version out now: http://blippy.net/?p=188

    Tuesday, December 27, 2016 at 8:37 am | Permalink
  4. Preston wrote:

    This is great & working well on my machine, thanks!

    Would it be possible to add another few lines of code to replace the 1366×768 in the URL with 1920×1080 before downloading? I know Bing offers a 1920×1080 version at that same URL if you just replace that little snippet, but I’m not versed on building shell scripts and don’t know how I’d edit the URL before downloading.

    For example, today’s:
    bing.com/az/hprichbg?p=rb%2fMtTaranaki_EN-US11002049684_1366x768.jpg
    would become:
    bing.com/az/hprichbg?p=rb%2fMtTaranaki_EN-US11002049684_1920x1080.jpg

    Any thoughts?

    Monday, March 2, 2015 at 6:27 pm | Permalink
  5. Preston wrote:

    Nevermind, I found a solution. I just added:

    # replace the 1366×768 image with a 1920×1080 image
    NewURL=${URL/1366×768/1920×1080}

    just after line 14 and then changed the “URL” variable at the end in the download section to “NewURL”

    Thanks again! 🙂

    Monday, March 2, 2015 at 7:16 pm | Permalink
  6. Rick wrote:

    Preston,
    I am also trying to download the higher resolution image. I understand your modifications but cant seem to get the script to work. Can you post your entire, modified script? Thx 🙂

    Wednesday, April 8, 2015 at 10:44 pm | Permalink
  7. MG wrote:

    There’s a new version out http://blippy.net/?p=188

    Tuesday, December 27, 2016 at 8:36 am | Permalink

2 Trackbacks/Pingbacks

  1. MG › Bing wallpaper on a Mac 2.0 on Monday, December 26, 2016 at 1:47 pm

    […] ‹ Bing wallpaper on a Mac […]

  2. MG › Bing wallpaper on a Mac 2.0 on Tuesday, December 27, 2016 at 9:09 am

    […] In my previous post, I shared my script to download Bing wallpapers for use on a Mac: Bing wallpaper on a Mac […]

Post a Comment

Your email is never published nor shared. Required fields are marked *
*
*