Seena

Bing Desktop for Ubuntu

Mar 29th, 2013
1,507
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.19 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3.  # $bing is needed to form the fully qualified URL for
  4.  # the Bing pic of the day
  5.  bing="www.bing.com"
  6.  
  7.  # $xmlURL is needed to get the xml data from which
  8.  # the relative URL for the Bing pic of the day is extracted
  9.  # The idx parameter determines where to start from. 0 is the current day,
  10.  # 1 the previous day, etc.
  11.  xmlURL="http://www.bing.com/HPImageArchive.aspx?format=xml&idx=0&n=1&mkt=en-US"
  12.  
  13.  # $saveDir is used to set the location where Bing pics of the day
  14.  # are stored. $HOME holds the path of the current user's home directory
  15.  saveDir=$HOME'/'
  16.  
  17.  # Create saveDir if it does not already exist
  18.  mkdir -p $saveDir
  19.  
  20.  # Set picture options
  21.  # Valid options are: none,wallpaper,centered,scaled,stretched,zoom,span ned
  22.  picOpts="zoom"
  23.  
  24.  # The desired Bing picture resolution to download
  25.  # Valid options: "_1024x768" "_1280x720" "_1366x768" "_1920x1200"
  26.  picRes="_1920x1200"
  27.  
  28.  # The file extension for the Bing pic
  29.  picExt=".jpg"
  30.  
  31.  # Extract the relative URL of the Bing pic of the day from
  32.  # the XML data retrieved from xmlURL, form the fully qualified
  33.  # URL for the pic of the day, and store it in $picURL
  34.  picURL=$bing$(echo $(curl -s $xmlURL) | grep -oP "<urlBase>(.*)</urlBase>" | cut -d ">" -f 2 | cut -d "<" -f 1)$picRes$picExt
  35.  
  36.  # Temporary Name
  37.  tempName="temp.jpg"
  38.  
  39.  # Download the Bing pic of the day
  40.  curl -s -o $saveDir$tempName $picURL
  41.  
  42.  # Get the description from the EXIF of the image
  43.  annotation=$(exiftool -s -s -s -Title "$saveDir$tempName")
  44.  
  45.  # Final Name given by Bing
  46.  picName=${picURL##*/}
  47.  
  48.  # Write the EXIF into the Wallpaper
  49.  convert $saveDir$tempName  -fill white  -undercolor '#00000080' -font Ubuntu-Regular -pointsize 24 -gravity Southeast -annotate +0+5 " $annotation " $saveDir$picName
  50.  
  51.  # Remove Temp
  52.  rm $saveDir$tempName
  53.  
  54.  # Set the GNOME3 wallpaper
  55.  DISPLAY=:0 GSETTINGS_BACKEND=dconf gsettings set org.gnome.desktop.background picture-uri '"file://'$saveDir$picName'"'
  56.  
  57.  # Set the GNOME 3 wallpaper picture options
  58.  DISPLAY=:0 GSETTINGS_BACKEND=dconf gsettings set org.gnome.desktop.background picture-options $picOpts
  59.  
  60.  # Remove pictures older than 7 days
  61.  # find $saveDir -atime 7 -delete
  62.  
  63.  # Exit the script
  64.  exit
Advertisement
Add Comment
Please, Sign In to add comment