emkay443

Random wallpaper

May 19th, 2014
487
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.13 KB | None | 0 0
  1. #!/bin/bash
  2. # Fetches a random wallpaper from /r/wallpapers
  3. # and sets xfdesktop's wallpaper to it
  4. #
  5. # Author: Michael Koch (emkay443) (and others on reddit: http://redd.it/25wkxa)
  6. # Version: 2014-05-19_1
  7. # License: GPL v3
  8.  
  9. # get XDG variables
  10. . $HOME/.config/user-dirs.dirs
  11.  
  12. # configuration
  13. wp_file=$XDG_PICTURES_DIR/wpotd
  14. random=true
  15. monitors=( 0 1 )
  16.  
  17. # helper variable
  18. if $random; then
  19.     url=$(curl -s http://www.reddit.com/r/wallpapers/.rss | grep -o "http://i.imgur.com/[/a-zA-Z0-9.]\+" | shuf -n 1)
  20. else
  21.     url=$(curl -s http://www.reddit.com/r/wallpapers/.rss | grep -o "http://i.imgur.com/[/a-zA-Z0-9.]\+" | head -1)
  22. fi
  23.  
  24. # download image
  25. wget -O $wp_file "$url"
  26.  
  27. # make sure, DBUS is loaded correctly (make this script work with cron)
  28. if [ -z "${DBUS_SESSION_BUS_ADDRESS}" ] ; then
  29.     . ${HOME}/.dbus/session-bus/`ls -rt ${HOME}/.dbus/session-bus/ | tail -1`
  30.         export DBUS_SESSION_BUS_ADDRESS
  31. fi
  32.  
  33. for mon in "${monitors[@]}"; do
  34.     # set xfdesktop's wallpaper and refresh
  35.     DISPLAY=:0 xfconf-query -c xfce4-desktop -p /backdrop/screen0/monitor$mon/image-path -s $wp_file
  36.     DISPLAY=:0 xfdesktop --reload
  37. done
Add Comment
Please, Sign In to add comment