It all started with our week as volunteers in the Mount Washington Observatory. All over that place you find the observatory’s weather panel and so I decided to make it a desktop background picture on my PC. Now this PC I am talking about is running Windows XP. It didn’t take long to find a background changer application. But then I needed to download and install wget (yes, that is not part of Windows). Like most Windows apps, the changer has a GUI and even in ‘hiding’ mode shows up prominently in the tray. So I started building a batch file that would download the panel and install it as background. After some headaches and downloading a few UNIX tools (the panel is a png file, Windows wants a bmp) it finally worked.
I said: “This MUST be MUCH easier on Linux!”
- wget, check!
- Gnome can use pngs, check!
The script “ChangeWallpaper” looks like this:
!#/bin/bash
cd /home/wallpaper
rm -f conditions.png
wget “http://mountwashington.org/weather/conditions.png”
gconftool-2 -t str –set /desktop/gnome/background/picture_filename “/home/wallpaper/conditions.png”
- run script, wallpaper changes, check!
NOT SO FAST!
The panel is updated ever 15 minutes, so in order to catch it I created a crontab like this:
*/5 * * * * /home/wallpaper/ChangeWallpaper
but that didn’t do anything.
Some digging leads to the solution:
GNOME uses dbus for Inter Process Communication (IPC). When I started the gconftool it had no information about dbus and therefore just exited. The dbus address that is used by clients to connect to the server is not available at in crontab and so we have to retrieve that address.
There are different ways to find that address, I like the one where you look at the nautilus application (kind of explorer) and export its DBUS_SESSION_BUS_ADDRESS:
export $(tr ‘\0′ ‘\n’ < /proc/$(pgrep nautilus)/environ | grep ‘^DBUS_SESSION_BUS_ADDRESS=’)
The full script is now:
!#/bin/bash
cd /home/local/wallpaper
rm -f conditions.png
wget “http://mountwashington.org/weather/conditions.png”
export $(tr ‘\0′ ‘\n’ < /proc/$(pgrep nautilus)/environ | grep ‘^DBUS_SESSION_BUS_ADDRESS=’)
gconftool-2 -t str –set /desktop/gnome/background/picture_filename “/home/local/wallpaper/conditions.png”
You may want to use the configuration editor to change /desktop/gnome/background/picture_options to ‘centered’. Feel free to poke around yourself.