SHARE
TWEET

Wallpaper Changer

mbpaster Apr 12th, 2014 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. #
  3. # WallpaperChanger.sh
  4. # Copyright 2014 Michele Bonazza michele@michelebonazza.com
  5. #
  6. # A simple script to automatically change your wallpaper in Gnome.
  7. #
  8. # This program is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation, either version 3 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with this program.  If not, see <http://www.gnu.org/licenses/>.
  20.  
  21. WALLPAPERS_FOLDER=/home/path/to/your/wallpapers
  22. REFRESH_INTERVAL=$((5 * 60)) # change every 5 minutes
  23. MODE="zoom" # one between none, centered, wallpaper, scaled, stretched, zoom, spanned
  24.  
  25. # Changes the desktop background, and moves it to the "shown" folder so that it's
  26. # not shown again before all wallpapers in the folder have been used.
  27. # arg1 the file name of the file to be set as new background; must be in the
  28. #      current folder
  29. function change_wallpaper() {
  30.   mv $1 shown
  31.   gsettings set org.gnome.desktop.background picture-uri file://$WALLPAPERS_FOLDER/shown/$1
  32.   gsettings set org.gnome.desktop.background picture-options $MODE
  33. }
  34.  
  35. # Echoes the next wallpaper to be set, picked at random among images in the
  36. # configured folder
  37. function get_next_wallpaper() {
  38.   find . -maxdepth 1 -type f -name "*.png" -o -name "*.jpg" -o -name "*.gif" -o -name "*.jpeg"| shuf -n 1
  39. }
  40.  
  41. mkdir -p $WALLPAPERS_FOLDER/shown
  42. cd $WALLPAPERS_FOLDER
  43.  
  44. while true; do
  45.   NEXT_WP=$(get_next_wallpaper)
  46.  
  47.   # have we used all wallpapers?
  48.   if [[ "$NEXT_WP" == "" ]]; then
  49.     # yes, chdir to shown, and move them all back to the parent folder
  50.     cd shown
  51.     # move them to parent folder
  52.     find . -maxdepth 1 -type f -name "*.png" -o -name "*.jpg" -o -name "*.gif" -o -name "*.jpeg" | xargs mv -t ..
  53.     cd ..
  54.  
  55.     # check again
  56.     NEXT_WP=$(get_next_wallpaper)
  57.  
  58.     if [[ "$NEXT_WP" == "" ]]; then
  59.       echo "no wallpapers found in $WALLPAPERS_FOLDER, will check again in $REFRESH_INTERVAL seconds..."
  60.       sleep $REFRESH_INTERVAL
  61.       continue
  62.     fi
  63.   fi
  64.  
  65.   echo "changing background to $NEXT_WP"
  66.   change_wallpaper $NEXT_WP
  67.   sleep $REFRESH_INTERVAL
  68. done
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top