banner
Previous Page
PCLinuxOS Magazine
PCLinuxOS
Article List
Disclaimer
Next Page

Get A New HD Wallpaper From Bing Every Day

by Paul Arnote (parnote)

Last month, I shared a script with you that downloads a new HD wallpaper from National Geographic. You can run it as often as you like -- daily if you want. I modified the original script to allow you to only download the images, or to set the newly downloaded image as the wallpaper for your current desktop environment.

This month, I'm sharing another script that downloads a new HD wallpaper from Bing. Say WHAT?! Bing? That search engine run by the "evil empire," Microsoft?! Why yes, the one and very same.

Regardless of what you think/feel about Microsoft, one thing that they do have is a new, high quality background image on their search page every single day. The images are typically high resolution, and make for some excellent wallpaper images. Since this script allows you to download them, you, me and everyone else might as well get something for free from Microsoft. For myself, and probably a lot of other users, therein lies the "sweet spot" of this script.

Compare the screenshot of Firefox displaying the Bing search engine, with the image obtained with the Bing wallpaper script, then used as my wallpaper.








This was the background image on August 28, 2013 (when I started writing this article), commemorating the 50th anniversary of the civil rights March on Washington, D.C., in 1963. All of the downloaded images are 1366x768 in dimension.


The script

Here is the script, in it's entirety. You can type it into a plain text editor (Kate, Kwrite, Mousepad, Leafpad, Geany, etc.), or copy and paste it from this article into a plain text editor. If you'd rather save yourself the trouble, you can download this script from the magazine's website. Be sure to remove the ".txt" file extension, save it to a location in your path, and make sure the file is marked as being executable. The easiest way to do the latter is to open a terminal session and type chmod +x path/to/script/bing.sh (provided you saved it as bing.sh).

#!/usr/bin/env bash

 # ********************************  
 # *** FUNCTIONS  
 # ********************************  

  function make_js {
    js=$(mktemp)
    cat > $js <<_EOF
      var wallpaper = "$PICTURE_DIR/$filename";
      var activity = activities()[0];
      activity.currentConfigGroup = new Array("Wallpaper", "image");
      activity.writeConfig("wallpaper", wallpaper);
      activity.writeConfig("userswallpaper", wallpaper);
      activity.reloadConfig();
_EOF
}
 function kde_wallpaper {
   make_js
   qdbus org.kde.plasma-desktop /MainApplication loadScriptInInteractiveConsole $js > /dev/null
   # sleep 2
   xdotool search --name "Desktop Shell Scripting Console -- 
Plasma Desktop Shell" windowactivate key ctrl+e key ctrl+w
   rm -f "$js"
   dbus-send --dest=org.kde.plasma-desktop /MainApplication org.kde.plasma-desktop.reparseConfiguration
   dbus-send --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.ReloadConfig
   dbus-send --dest=org.kde.kwin /KWin org.kde.KWin.reloadConfig
   # kbuildsycoca4 2>/dev/null && kquitapp plasma-desktop 2>/dev/null ; kstart plasma-desktop > /dev/null 2>&1
 }
 function xfce_wallpaper {
   xfconf-query -c xfce4-desktop -p /backdrop/screen0/monitor0/image-path -s $PICTURE_DIR/$filename
 }
 function lxde_wallpaper {
   pcmanfm -w "$PICTURE_DIR/$filename"
 }
 function mate_wallpaper {
   gsettings set org.mate.background picture-filename $PICTURE_DIR/$filename
 }
 function e17_wallpaper {
   OUTPUT_DIR=~/.e/e/backgrounds
   FileName=$PICTURE_DIR/$filename
   edcFile=~/tmp/Bing.edc

   echo 'images { image: "'$FileName'" LOSSY 90; }' > $edcFile
   echo 'collections {' >> $edcFile
   echo 'group { name: "e/desktop/background";' >> $edcFile
   echo 'data { item: "style" "4"; }' >> $edcFile
   echo 'data.item: "noanimation" "1";' >> $edcFile
   echo 'max: 990 742;' >> $edcFile
   echo 'parts {' >> $edcFile
   echo 'part { name: "bg"; mouse_events: 0;' >> $edcFile
   echo 'description { state: "default" 0.0;' >> $edcFile
   echo 'aspect: 1.334231806 1.334231806; aspect_preference: NONE;' >> $edcFile
   echo 'image { normal: "'$FileName'";  scale_hint: STATIC; }' >> $edcFile
   echo '} } } } }' >> $edcFile
   edje_cc -nothreads ~/tmp/Bing.edc -o $OUTPUT_DIR/Bing.edj
   sleep 2 && rm -f ~/tmp/Bing.edc
   echo 'Enlightenment e17 Bing.edj file created'
   enlightenment_remote -desktop-bg-del 0 0 -1 -1
   enlightenment_remote -desktop-bg-add 0 0 -1 -1 $OUTPUT_DIR/Bing.edj;
 }
 function usage {
   printf "%s\n%s\n\n%s\n%s\n\n%s\n\n%s" \
   "Bing will download the Bing Wallpaper Of The Day,"\
   "and (optionally) set that picture as the new wallpaper."\
   "Based on original script by thejandroman, and expanded by Paul Arnote for PCLinuxOS."\
   "Originally published in The PCLinuxOS Magazine (http://pclosmag.com), Oct. 2013 issue."\
   "Works for KDE4, Xfce, LXDE, Mate and e17 desktops."\
   "Usage: $0 [arguments]"\

   printf "\n %s\t%s" \
   "-h, --help" "This help text"
   printf "\n %s\t\t%s" \
   "-d" "Download pictures ONLY"
   printf "\n %s\t\tSetup for the %s" \
   "--xfce"    "XFCE4 Desktop"\
   "--mate"    "Mate Desktop"\
   "--lxde"    "LXDE Desktop"\
   "--kde4"    "KDE4 Desktop"\
   "--e17"    "Enlightenment Desktop"
   printf "\n"
 }

 # ********************************  
 # *** MAIN  
 # ********************************  

 if [ "$1" == "--help" ] || [ "$1" == "-h" ] || [ "$1" == "" ]; then
   usage
   exit
 fi

 echo "===================="  
 echo "== Bing Wallpaper =="  
 echo "===================="  

PICTURE_DIR=~/Wallpaper/Bing/

mkdir -p $PICTURE_DIR

sleep 1

urls=( $(curl -s http://www.bing.com|grep -Eo "url:'.*?'"|sed -e "s/url:'\([^']*\)'.*/
http:\/\/bing.com\1/"|sed -e "s/\\\//g") )

for p in ${urls[@]}; do
filename=$(echo $p|sed -e "s/.*\/\(.*\)/\1/")
    if [ ! -f $PICTURE_DIR/$filename ]; then
echo "Downloading: $filename ..."
    curl -Lo "$PICTURE_DIR/$filename" $p
    else
echo "Skipping: $filename ..."
    fi
done

   if [ "$1" != "-d" ]; then
     echo "Setting image as wallpaper"
   fi

   # For Xfce
   if [ "$1" == "--xfce" ]; then
     xfce_wallpaper
   fi
   # For LXDE
   if [ "$1" == "--lxde" ]; then
     lxde_wallpaper
   fi
   # For Mate
   if [ "$1" == "--mate" ]; then
     mate_wallpaper
   fi
   # For KDE4
   if [ "$1" == "--kde4" ]; then
     kde_wallpaper
   fi
   # For e17
   if [ "$1" == "--e17" ]; then
     e17_wallpaper
   fi

Modifications

To make this work for all of the mainstream desktops offered for PCLinuxOS, I borrowed the functions from the NatGeo script to automatically set the wallpaper for your chosen desktop environment. So, the script works exactly the same way as the NatGeo script from last month. Instead of repeating all of the same information here, I'll refer you to the discussion in last month's magazine article, particularly the "Notes About The Desktops" section. Since I had already done the "heavy work" by creating the functions to set the wallpaper for each desktop environment in the NatGeo script, it only made sense to reuse that code.

However, it is important to reiterate two items. First, e17 users must enable DBus Extensions module, or the script will not be able to change/set the desktop wallpaper. Second, KDE4 users will need to install xdotool from Synaptic in order for the script to set the desktop wallpaper. Users of Xfce, Mate and LXDE don't need to do anything special, except to run the script. Please refer to the NatGeo article (previous link) and review the other notes.


Usage

The usage of the script is identical to the usage rules for the NatGeo script. Why reinvent the wheel? When you find something that works and works well, you might as well stick with it. Right?

$ bing.sh
Bing will download the Bing Wallpaper Of The Day,
and (optionally) set that picture as the new wallpaper.

Based on original script by thejandroman, and expanded by Paul Arnote for PCLinuxOS.
Originally published in The PCLinuxOS Magazine (http://pclosmag.com), Oct. 2013 issue.

Works for KDE4, Xfce, LXDE, Mate and e17 desktops.

Usage: /home/parnote-t42/Scripts/bing.sh [arguments]
 -h, --help    This help text
 -d             Download pictures ONLY
 --xfce        Setup for the XFCE4 Desktop
 --mate        Setup for the Mate Desktop
 --lxde        Setup for the LXDE Desktop
 --kde4        Setup for the KDE4 Desktop
 --e17        Setup for the Enlightenment Desktop

If you type either bing.sh, bing.sh -h or bing.sh --help in a terminal session, you will get the text above displayed in the terminal screen. If you type bing.sh -d, the wallpapers will be downloaded to your computer, but it will skip setting the image as your wallpaper. To download the image of the day and set that new image as your desktop wallpaper, supply the appropriate command line option for your selected desktop (--xfce for the Xfce desktop, --mate for the Mate desktop, --lxde for the LXDE desktop, --kde4 for the KDE4 desktop, and --e17 for the Enlightenment e17 desktop). There is virtually no error checking to insure that you enter the right command, just to keep the script size small.

When you run the script, you will see the following displayed in the terminal window:

$ bing.sh --xfce
====================
== Bing Wallpaper ==
====================
Downloading: MarchonWA_EN-US13404932946_1366x768.jpg ...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100  119k  100  119k    0     0   195k      0 --:--:-- --:--:-- --:--:--  955k
Setting image as wallpaper

The script will inform you that it is downloading a new image, and then setting it as your desktop wallpaper.

$ bing.sh --xfce
====================
== Bing Wallpaper ==
====================
Skipping: MarchonWA_EN-US13404932946_1366x768.jpg ...
Setting image as wallpaper

If you've already downloaded the Bing "image of the day," the bing.sh script will skip downloading it again, but still set that image as your desktop wallpaper. This makes it easy to switch back to the Bing wallpaper image of the day if you've previously downloaded it and then changed your wallpaper to something else. Just rerun the bing.sh script.


Summary

Between the NatGeo and Bing wallpaper scripts, no PCLinuxOS user should ever worry about having or finding wallpaper image files. Both scripts retrieve very high quality images that make perfect wallpaper images for any computer user's desktop.



Previous Page              Top              Next Page
Copyright (c) 2013, The PCLinuxOS Magazine. All Rights Reserved.