This script worked fine, but a few months ago it stopped updating my desktop. Today I had some time and tracked down the problem to the
gsettings command. The script sets the background with this external command:
gsettings set org.gnome.desktop.background picture-uri file:///absolute/path/to/image.jpg
When I launched the script manually, the background was refreshed. However, when it was called from crontab, the background was not refreshed.
gsettings actually set the new image, but the background was not refreshed, so I still saw the old image. Wat?
I found the solution here. As Radu Rădeanu points out, the only environment variable that is required to run the script correctly as a cron job is the
GSETTINGS_BACKEND or something else.
Here is how to set the value of DBUS_SESSION_BUS_ADDRESS:
PID=$(pgrep gnome-session) export DBUS_SESSION_BUS_ADDRESS=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$PID/environ|cut -d= -f2-)
Now my crontab file looks like this:
HOME=/home/jabba DISPLAY=:0 PYTHONPATH=$PYTHONPATH:$HOME/python/lib/jabbapylib 0 0 * * * $HOME/bin.python/bing.sh
The source of bing.sh:
#!/usr/bin/env bash HOME=/home/jabba DISPLAY=:0 PYTHONPATH=$PYTHONPATH:$HOME/python/lib/jabbapylib PID=$(pgrep gnome-session) export DBUS_SESSION_BUS_ADDRESS=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$PID/environ|cut -d= -f2-) DIR=$HOME/Dropbox/python/lib/jabbapylib/jabbapylib/apps $DIR/bing.py >>$HOME/bing.log.txt
You browse the web and you find a nice image file. “Hey, it’d look cool on my desktop!” Or, you browse your local image files: “Hey, I want to see it as my wallpaper!” How to set a background image painlessly?
With jabbapylib, of course :) Just use my new little script:
# the image is on the web: set_wallpaper http://i.imgur.com/t1FRG.jpg # the image is a local file: set_wallpaper sunshine.png
Under Gnome you could set the wallpaper from command line with the following commands:
gconftool-2 --type=string --set /desktop/gnome/background/picture_filename /path/to/image.jpg gconftool-2 --type=string --set /desktop/gnome/background/picture_options stretched # stretch the image
You try it again on a newer Ubuntu that uses Unity, and nothing happens! What’s going on?
The new way of setting a wallpaper is this:
gsettings set org.gnome.desktop.background picture-uri file:///path/to/img.jpg
Notice that you must provide a URI, hence the “
The first snippet works with Gnome 2. The second one is for Gnome 3. To figure out your Gnome version, launch the command “
Update (20110915): The project has changed a lot since its first release, thus the original post here got completely outdated. I rewrote this blog entry to reflect the current state of the project.
The goal of this project is twofold. First, download images from a wallpaper site. Second, rotate the downloaded images as wallpapers.
Here is the list of changes that I added to the original version:
- New! XML support is dropped. For setting the images as wallpapers, use the script
- New! Support for 4walled.org is added!
- New! Support for wallbase.cc is added!
- Large images can be resized to fit your screen resolution. By default, the maximum width of images can be 1920 pixels. You can customize it in the config file. It’s recommended, this way the images will occupy much less space on your hard drive.
- You can specify several categories and the downloader will grab images from all these sites. The same is true for rotator: you can specify several categories and it will pick a random image from the whole list. See the config file for more details.
- The project includes an automatic wallpaper changer script called
02_wallpaper_rotator.py. You don’t need any third-party managers anymore.
- You can choose from several categories. You can also specify your favorite category.
- Screen scraping is done with the BeautifulSoup library.
- The most important change is the filtering of images that are unsuitable as wallpapers, i.e. small images, portrait images, and images with strange ratio are removed from the list.
- Support for Flickr images (zioyero’s patch).
- The URLs of the downloaded images are strored in an SQLite database. This way an already fetched image (either good or bad) won’t be downloaded again.
Supported wallpaper sites
First, you might want to customize some settings in the
config.py file. The most important thing is the
PHOTO_DIR directory, i.e. where to store the downloaded images. Create this directory if it doesn’t exist. Then, simply launch the script:
You can also add it to your crontab:
$ crontab -e 10 */2 * * * /absolute_path_to/01_wallpaper_downloader.py
Add the second line to the end of the crontab list. Here the script is called at every two hours (at 0h10, 2h10, etc.).
For setting the images as wallpapers:
That is, just launch it in the background. It uses the same config file as the wallpaper downloader. I put it among my startup applications, thus it starts automatically.
You can download the script from https://github.com/jabbalaci/Wallpaper-Downloader-and-Rotator-for-Gnome.
You have a bunch of nice wallpaper images that you would like to see on your Desktop. You want Gnome to rotate them in a circular way. Also, specify the duration of an image and the transition between two images.
You need to create an XML file similar to this:
<?xml version='1.0'?> <background> <starttime> <hour>00</hour> <minute>00</minute> <second>01</second> </starttime> <static> <duration>10.0</duration> <file>/trash/wallpapers/A.jpg</file> </static> <transition> <duration>5.0</duration> <from>/trash/wallpapers/A.jpg</from> <to>/trash/wallpapers/B.jpg</to> </transition> <static> <duration>10.0</duration> <file>/trash/wallpapers/B.jpg</file> </static> <transition> <duration>5.0</duration> <from>/trash/wallpapers/B.jpg</from> <to>/trash/wallpapers/C.jpg</to> </transition> <static> <duration>10.0</duration> <file>/trash/wallpapers/C.jpg</file> </static> <transition> <duration>5.0</duration> <from>/trash/wallpapers/C.jpg</from> <to>/trash/wallpapers/A.jpg</to> </transition> </background>
Here, I rotate three images. One image is shown for 10 seconds and the transition is done smoothly in 5 seconds. After the third image, the first image is shown again, i.e. Gnome will restart processing the file from the beginning.
Usage: You will have to specify this XML file as your background. Right click on the Desktop, Change Desktop Background, Background tab, Add… button. In the bottom right hand corner, switch from Images to All files, then select the XML file. See this screenshot.
Note: Once you set the XML file as your background, you can update it. Gnome will notice the changes and the file will be reloaded. That is, you don’t need to set the file as your background after each modification.
- Creating a rotating wallpaper “stack” for your Ubuntu 10.04 (and other Gnome 2.28) system
- Generating Gnome Rotating Backgrounds
I will collect here some links with cool wallpapers:
- wallpaper and wallpapers on wordpress.com
- http://www.geekwallpapers.com/, http://www.sciencewallpaper.com/, http://www.knifewallpapers.com/
- Gnome wallpapers
Cool images on reddit (don’t be afraid of the ‘Porn’ titles, it’s not what it seems to be):
- EarthPorn: Mother Nature in all of her succulent beauty. (great)
- CityPorn: Oh pedobear, it’s not that kind of CP, silly! (great)
- SpacePorn: High Res Images of Space, Stargazer’s Delight (great)
- MachinePorn: Check out the headlights on that porsche. I think my driveshaft just got torqued.
- Human Porn: Beauty is in the eye of the beholder
- AnimalPorn: High quality animal photography will make you shiver and moan (great)
- BotanicalPorn: Feed me Seymour. Feeeed meeeeeee! (nice)
- DestructionPorn: Burn Baby Burn!
- AdPorn: Where’s the beef?
- *Porn: all the previous together
You have a bunch of images that you would like to see as your desktop wallpapers. You are looking for an application that could rotate these images periodically.
Try Wally. Just specify the directory where the images are located, set the time interval, and go. Wally runs on Windows, Linux, and Mac OSX.
sudo apt-get install wally
Wally knows a lot more; for a more detailed description check out this post.
About a year ago, I used another application for this task called
wallpaper-tray. However, this package is gone from Synaptic, it seems it has been replaced by
Update (20110509) [Unity patch]
Wally exists in the system tray. However, Ubuntu 11.04 introduced Unity that comes with a new top panel and applications are not allowed to be there by default. You need to enable explications explicitly. If you want to continue using wally, here is what to do:
First, get your current settings for systray-whitelist:
gsettings get com.canonical.Unity.Panel systray-whitelist
Then, add your application to the above list with this command:
gsettings set com.canonical.Unity.Panel systray-whitelist "[ your_previous_list_here, 'wally']"
This tip is from Antonio, the author of wally.
If you want to download cool wallpapers, you may want to check out my Wallpaper Downloader and Rotator for Gnome. It can be used as a downloader and you can pass the rotating job to wally.