Skip to content

Instantly share code, notes, and snippets.

@elundmark
Created February 22, 2013 02:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elundmark/5010343 to your computer and use it in GitHub Desktop.
Save elundmark/5010343 to your computer and use it in GitHub Desktop.
Live Webcam Wallpaper Script for Ubuntu
#!/bin/bash
# Updates your desktop with an hourly updated image from (in this case Ocean Beach, SF) a webcam jpeg url.
# Uses: cronjob, curl, convert, gsettings
# Example screenshot: https://dl.dropbox.com/u/1907097/live_webcam_wallpaper_ubuntu.png
# My cronjob setup, runs on minute :01 every hour
# 1 * * * * /path/to/live_webcam_wallpaper_ubuntu.sh &> /dev/null
if [[ -z "$DBUS_SESSION_BUS_ADDRESS" ]]; then
source "$HOME/.dbus/session-bus"/*-0 && export DBUS_SESSION_BUS_ADDRESS
fi
# The -break image is to ensure Ubuntu reloads the image, and we son't want to keep all the old images
SFIMG="/path/to/webcam-wall.jpg"
RMIMG="/path/to/webcam-wall-break.jpg"
if [ -f "$SFIMG" ]; then
SFIMG="/path/to/webcam-wall-break.jpg"
RMIMG="/path/to/webcam-wall.jpg"
fi
DISPLAY=:0.0 curl -L --silent --user-agent "Mozilla/5.0 (X11; Linux i686) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.43 Safari/536.11" \
--referer "http://ob-kc.com/current.html" "http://ob-kc.com/images/current_lg.jpg" -o "$SFIMG"
if [ ! $? -eq 0 ]; then
exit 1
fi
FILE_MIME=$(file -b "$SFIMG")
# Ensure we got an image and not an error (textfile)
if [[ "$FILE_MIME" =~ ^JPEG ]]; then
LOCALTIME="$(date +'%s')"
# This is specific to my script, it sets the clock back 9 hours for San Francisco <> Sweden
#LOCALTIME=$((LOCALTIME - 32400))
DATE="$(date --date="@$LOCALTIME" +'%Y-%m-%d %H:%M')"
# Resize to fit my display, and add the timestamp
DISPLAY=:0.0 /usr/bin/convert "$SFIMG" -auto-orient -quality 100 -resize 1366^x768 -gravity center -crop 1366x768+0+ \
-font Ubuntu-Regular -pointsize 20 -fill black -annotate +570+346 "$DATE" -fill white -annotate +571+345 "$DATE" "$SFIMG"
if [ ! $? -eq 0 ]; then
exit 1
fi
sleep 1
# For Ubuntu 12.10
DISPLAY=:0.0 gsettings set org.gnome.desktop.background picture-uri file://$SFIMG
# This might be the right way for [other dists / gnome]
# DISPLAY=:0.0 gconftool-2 --type string --set /desktop/gnome/background/picture_filename "$SFIMG"
sleep 1
rm "$RMIMG"
exit 0
else
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment