REFRESH YOUR MAC DESKTOP WITH BING HOMEPAGE

Everyone would agree that Bing Homepage Wallpaper are cool and refreshing daily. If you are on Mac you would be little jealous with Windows 8 desktop Wallpaper, which are refreshed on daily basis. Well, after looking around, I got the solution which refreshes your Mac desktop with Bing Daily Homepage.

1. Create a shell script file, bing-wallpaper.sh (you can rename it whatever you want):

#!/usr/bin/env bash

PICTURE_DIR="$HOME/Pictures/Bing-Wallpapers"

mkdir -p $PICTURE_DIR

urls=( $(curl -s http://www.bing.com | \
    grep -Eo "url:'.*?'" | \
    sed -e "s/url:'\([^']*\)'.*/http:\/\/bing.com\1/" | \
    sed -e "s/\\\//g") )

if [ "$urls" != "" ]
then
    rm -Rf $PICTURE_DIR/*.*

#   Use this for today's Bing Wallpaper
    filename=$(echo $urls|sed -e "s/.*\/\(.*\)/\1/")
    curl -Lo "$PICTURE_DIR/$filename" $urls
        
#   Use this for today's and next day's Bing Wallpaper
#      
#   for p in ${urls[@]}; do
#       filename=$(echo $p|sed -e "s/.*\/\(.*\)/\1/")
#       if [ ! -f $PICTURE_DIR/$filename ]; then
#           echo "Downloading: $filename ..."
#           curl -Lo "$PICTURE_DIR/$filename" $p
#       else
#           echo "Skipping: $filename ..."
#       fi
#   done

    killall Dock
    exit 0
fi

exit 99

2. Provide execute rights on this file

chmod +x /Applications/Custom\ Apps/bing-wallpaper.sh

3. Create launchd scheduled job (com.yourname.bing-wallpaper.plist file) to run it every morning 7 AM and execute our shell script (create in Step #1)

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
   <key>Label</key>
   <string>com.yourname.bing-wallpaper</string>
   <key>ProgramArguments</key>
   <array>
      <string>/bin/bash</string>
      <string>/Applications/Custom Apps/bing-wallpaper.sh</string>
   </array>
   <key>LowPriorityIO</key>
   <true/>
   <key>Nice</key>
   <integer>1</integer>
    <key>KeepAlive</key>
    <dict>
        <key>SuccessfulExit</key>
        <false/>
    </dict>
    <key>RunAtLoad</key>
    <true/>
    <key>StartCalendarInterval</key>
    <dict>
      <key>Hour</key>
      <integer>7</integer>
      <key>Minute</key>
      <integer>0</integer>
    </dict>  
</dict>
</plist>

4. Copy this file to $HOME/Library/LaunchAgents folder

cp /folder/location/of/com.yourname.bing-wallpaper.plist $HOME/Library/LaunchAgents

5. Generally launchd load these jobs on login but you can load it manually

launchctl load $HOME/Library/LaunchAgents/com.yourname.bing-wallpaper.plist

If required, you can disable this job using following command –

launchctl unload $HOME/Library/LaunchAgents/com.yourname.bing-wallpaper.plist

You can find the status of job using the following command –

launchctl list | grep com.yourname

One thought on “REFRESH YOUR MAC DESKTOP WITH BING HOMEPAGE”

Leave a Reply