Autoupdate the desktop background from an online photo webcam I would like to set my desktop background to a webcam picture that updates several times an hour, for instance to this view of Tegernsee. I am looking for a way to automatically get that picture every couple of minutes from the internet and update the desktop background. How can I do that (I would prefer a bash or applescript solution)?
I have found a way to make this work with launchd. This requires two steps: First creating a script that downloads the webcam picture, and second creating a LaunchAgent plist file that will call the script every so often.

This method will update the background picture of a specific Space, but only while you are on that space (also, when logging in and maybe when waking from sleep).

First step: Creating a script that downloads the picture and changes the desktop background


Create a folder, e.g. ~/Library/Desktop Pictures/Webcam.
Select that folder to be your desktop backgrounds folder in System Preferences → Destkop &amp; Screen Saver.
Write a text file with the following content:

#!/bin/bash
shopt -s extglob # required for fancy rm
# This script updates the desktop background of a specific Space to a webcam picture
# while you are currently on that space.
#
# Choose a webcam:

remotepic=http://www.foto-webcam.org/webcam/wallberg/current/full.jpg

# Choose a desktop backgrounds pictures folder of the Space where you want to see the webcam
# (you have to set this manually in System Preferences → Destkop &amp; Screen Saver):

webcampicturefolder=~/Library/Desktop\ Pictures/Webcam

# check the desktop background pictures folder of the current Space
currentpicturefolder=`osascript -e "tell application \"System Events\" to get pictures folder of current desktop"`
# only proceed if you are currently on the space where you want to see the webcam
if [ "$currentpicturefolder" == "$webcampicturefolder" ] ; then
  localpic="$webcampicturefolder"/$(date +%Y%m%dT%H%M%S).jpg
  backup="$webcampicturefolder"/backup.jpg
  #remove all but the previous backup file and txt files:
  rm "$webcampicturefolder"/!(*txt|`basename "$backup"`) 2&gt;&gt;/dev/null
  # get the new picture unless there is a connection failure (-f flag):
  curl -fs -o "$localpic" "$remotepic"
  # make a backup of the new picture:
  cp "$localpic" "$backup" 2&gt;&gt;/dev/null
  # if no new picture has been downloaded, copy from backup:
  cp "$backup" "$localpic"
  # see http://www.macosxautomation.com/applescript/features/system-prefs.html
  osascript -e "
  tell application \"System Events\"
    tell current desktop
      set picture rotation to 0
      set picture to POSIX file \"$localpic\"
    end tell
  end tell
  "
fi

Save the file, e.g. as ~/Library/Desktop Pictures/Webcam/getwebcam.sh
Make it executable by issuing the following command in the Terminal:

chmod u+x ~/Library/Desktop Pictures/Webcam/getwebcam.sh



Second step: Creating a LaunchAgent plist that calls the script


Write a text file with the following content. You need to adapt the string /Users/myusername/Library/Desktop Pictures/Webcam/getwebcam.sh so it points to the script created in the first step. You cannot use a relative path with ~. Change the dict elements with the "Minute" key as you see fit – you can add more of them. The integer determines at which minute of every hour the script will be called (see also man launchd.plist on your Terminal).

&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt;
&lt;plist version="1.0"&gt;
&lt;dict&gt;
  &lt;key&gt;Label&lt;/key&gt;
  &lt;string&gt;me.myname.update-desktop-from-webcam&lt;/string&gt;
  &lt;key&gt;ProgramArguments&lt;/key&gt;
  &lt;array&gt;
    &lt;string&gt;/Users/myusername/Library/Desktop Pictures/Webcam/getwebcam.sh&lt;/string&gt;
  &lt;/array&gt;
  &lt;key&gt;RunAtLoad&lt;/key&gt;
  &lt;true/&gt;
  &lt;key&gt;StartCalendarInterval&lt;/key&gt;
  &lt;array&gt;
    &lt;dict&gt;
      &lt;key&gt;Minute&lt;/key&gt;
      &lt;integer&gt;01&lt;/integer&gt;
    &lt;/dict&gt;
    &lt;dict&gt;
      &lt;key&gt;Minute&lt;/key&gt;
      &lt;integer&gt;16&lt;/integer&gt;
    &lt;/dict&gt;
    &lt;dict&gt;
      &lt;key&gt;Minute&lt;/key&gt;
      &lt;integer&gt;31&lt;/integer&gt;
    &lt;/dict&gt;
    &lt;dict&gt;
      &lt;key&gt;Minute&lt;/key&gt;
      &lt;integer&gt;46&lt;/integer&gt;
    &lt;/dict&gt;
  &lt;/array&gt;
&lt;/dict&gt;
&lt;/plist&gt;

Save the text file to ~/Library/LaunchAgents/me.myname.update-desktop-from-webcam.plist – the name should match the "Label" key in the file.
Load it by issuing the following command:

launchctl load ~/Library/LaunchAgents/me.myname.update-desktop-from-webcam.plist