Menu

Home

ph_z

What this script does

  • checks if internet connection is available
  • downloads image of the day from www.bing.com
  • downloads image caption
  • optionally adds image caption to image, at top or bottom
  • sets the image as wallpaper for the requested desktop environment

Requirements / dependencies

  • Bash (Linux and Mac OSX ship with bash, on Windows you have to install Cygwin)
  • wget (Linux, Cygwin) or curl (Mac OSX)
  • imagemagick (only if you want to include caption in image)
  • some basic GNU system tools like getopts, ping, cut, grep, etc.

Supported environments

  • GNU/Linux with GNOME
  • GNU/Linux with Cinnamon
  • GNU/Linux with Xfce
  • GNU/Linux with MATE
  • Mac OSX (Leopard or newer)
  • Windows with Cygwin
  • Probably *BSD and other Unix flavors work as well, but I haven't tried.

Installation

setBingWP.sh is only one single bash script. Download it and put it into any directory, don't forget to make it executable. Run it manually first and experiment with the command line switches until you are satisfied with the result. When testing, don't forget to use the -l switch, otherwise most desktop environments won't update the wallpaper as the file name hasn't changed. On Linux, that's all there is to it.

On windows, you have to install Cygwin first (http://cygwin.com). Make sure you select wget and imagemagick as well in the Cygwin installer as they're not included by default. Then, if you want to include image captions, copy the file C:\Windows\Fonts\arial.ttf to C:\cygwin64\usr\share\fonts\TTF\arial.ttf (you have to create the TTF directory first). Download the setBingWP.sh Script and the HelperFiles Directory including all content and leave the directory structure as is.

On the Mac, you can get imagemagick from http://cactuslab.com/imagemagick/. The installation is identical to Linux.

Synopsis

Run setBingWP.sh -h to display the help:

Usage: setBingWp.sh -d [MATE|GNOME|CINNAMON|XFCE|OSX|WIN] [-c] [-r] [-o [TOP|BOTTOM]] [-i /path/to/images/dir] [-p [2-64]] [-s [8-24]] [-l] [-m [CONSOLE|SILENT|FILE]] [-w [CENTER|STRETCH|KEEP]]

Command line switches:
   -d sets the desktop environment (one of MATE, GNOME, CINNAMON, XFCE, OSX, WIN). Required, no default.
   -c includes the Bing image caption into the wallpaper (requires imagemagick to be installed)
   -o sets the caption's orientation to either TOP or BOTTOM of image. Default is TOP.
   -r removes previously downloaded images
   -i sets the directory, where the bing images are stored (directory must exist, the script won't create it). Default is ~/Pictures/bing
   -p position of caption (distance from border of image, right value depends on screen size and resolution), value must be between 2 and 64. Default is 2.
   -s caption font size in points. Value between 8 and 24. Default is 16.
   -l use long file names (bingImage_YYYY-MM-DD_hh-mm-ss.jpg) instead of short ones (bingImage_YYYY-MM-DD.jpg)
   -m : set log mode: CONSOLE, SILENT or FILE (default is CONSOLE). When set to FILE, it will log to /tmp/setBingWP.log
   -w : position of wallpaper: CENTER, STRETCH or KEEP (default is KEEP)

Automation

Of course you can just run the script by hand, but must probably you'll want to automate this task. On a Linux PC that's up and running most of the time, you could just set up a cron job to run it e.g. once a day. The most convenient way on most boxes, however, is to have it run on whan you log in.

Linux

There are multiple ways to achieve this on Linux, and some of them depend on your desktop environment:

  • Cinnamon: Open Menu - Settings - Startup Applications and create a new task there.
  • Xfce: tbd
  • GNOME: tbd
  • MATE: tbd

Windows

On Windows it's most convenient to create a small batch file that you can simply launch by double-clicking on it. Mine looks like this:

set PATH=C:\cygwin64\bin;%PATH%
C:\cygwin64\bin\bash.exe /cygdrive/c/Path/to/Script/SetBingWP/setBingWP.sh -d WIN -c -i /cygdrive/c/Daten/Bilder/bing -w CENTER

You can then execute that batch file using Windows' task scheduler.

Mac OSX

The best option is to use launchd (see http://stackoverflow.com/questions/6442364/running-script-upon-login-mac/13372744#13372744)

First, create the directory ~/bin/ and put setBingWP.sh in ~/bin/. Then, create a second script, ~/bin/runSetBingWP.sh, containing e.g.

  #!/bin/bash
  /Users/YourUserName/bin/setBingWP.sh -d OSX

Then, create the directory ~/Library/LaunchAgents and the file ~/Library/LaunchAgents/com.user.setbingwp.plist containing

  <?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.user.setbingwp</string>
        <key>Program</key>
        <string>/Users/YourUserName/bin/runSetBingWP.sh</string>
        <key>RunAtLoad</key>
        <true/>
     </dict>
  </plist>

Finally, run the command launchctl load ~/Library/LaunchAgents/com.user.setbingwp.plist

Project Members: