Guest

Untitled

By: a guest on Feb 9th, 2010  |  syntax: Bash  |  size: 1.89 KB  |  hits: 129  |  expires: Never
download  |  raw  |  embed  |  report abuse
Copied
  1. #!/bin/bash
  2. #
  3. # Description:
  4. # This is a script to randomly select an image from a given directory
  5. # and automagicly change the desktop background to the selected image
  6. # in an Ubuntu Gnome environment. Developed and tested in Ubuntu 9.10
  7. #
  8. # License:
  9. # You may freely use, modify and redistribute this script as long as you allow others to do the same.
  10. # This script is provided without warranty or even fitness for purpose. Use at own risk.
  11. #
  12. ############### Configuration #####################################
  13. #
  14. # Set this variable to wherever you store your background images
  15. # Ubuntu default background storage is in /usr/share/backgrounds
  16. BACKGROUND_LOC="/usr/share/backgrounds/"                
  17. #
  18. ###################################################################
  19. #
  20. ### Code starts here. Do not modify below this line ###
  21.  
  22. ## Pick new image function
  23. pick_new_bg () {
  24.         backgrounds=( $( < ~/.background_temp) )
  25.         num_backgrounds=${#backgrounds[*]}
  26.         NEW_BACKGROUND=$(echo -n "${backgrounds[$((RANDOM%num_backgrounds))]}")
  27. }
  28.  
  29. ## Get and export the DBUS_SESSION_BUS_ADDRESS for crontab compatibility
  30. nautilus_pid=$(pgrep -u $LOGNAME -n nautilus)
  31. eval $(tr '\0' '\n' < /proc/$nautilus_pid/environ | grep '^DBUS_SESSION_BUS_ADDRESS=')
  32. export DBUS_SESSION_BUS_ADDRESS
  33.  
  34. ## Find image titles in specified directory
  35. ls $BACKGROUND_LOC | egrep -i ".jpg|.png" > ~/.background_temp
  36.  
  37. ## Pick new background image
  38. pick_new_bg
  39.  
  40. ## Get file name of current background and ensure the new background is different
  41. CURRENT_BACKGROUND=$(/usr/bin/gconftool-2 --get /desktop/gnome/background/picture_filename | xargs basename)
  42.  
  43. while [ $NEW_BACKGROUND == $CURRENT_BACKGROUND ]
  44. do
  45.         pick_new_bg
  46. done
  47.  
  48. ## Set the new background and remove the temp file
  49. /usr/bin/gconftool-2 --type string --set /desktop/gnome/background/picture_filename $BACKGROUND_LOC/$NEW_BACKGROUND
  50.  
  51. rm ~/.background_temp
  52.  
  53. # The End.