Advertisement
Guest User

Crontab wallpaper slideshow

a guest
Jul 7th, 2014
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.35 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Search these processes for the session variable
  4. # (they are run as the current user and have the DBUS session variable set)
  5. compatiblePrograms=( nemo pulseaudio trackerd nautilus )
  6.  
  7. # Attempt to get a program pid
  8. for index in ${compatiblePrograms[@]}; do
  9.     PID=$(pidof -s ${index})
  10.     if [[ "${PID}" != "" ]]; then
  11.         break
  12.     fi
  13. done
  14. if [[ "${PID}" == "" ]]; then
  15.     echo "Could not detect active login session"
  16. fi
  17.  
  18. QUERY_ENVIRON="$(tr '\0' '\n' < /proc/${PID}/environ | grep "DBUS_SESSION_BUS_ADDRESS" | cut -d "=" -f 2-)"
  19. if [[ "${QUERY_ENVIRON}" != "" ]]; then
  20.  
  21.     export DBUS_SESSION_BUS_ADDRESS="${QUERY_ENVIRON}"
  22.     # echo "Connected to session:"
  23.     # echo "DBUS_SESSION_BUS_ADDRESS=${DBUS_SESSION_BUS_ADDRESS}"
  24.  
  25.  # Script to randomly set Background from files in a directory
  26.  
  27.  # Directory Containing Pictures is given via command-line, could be hardcoded in there as well
  28.  DIR=$1
  29.  
  30.  #DIR="/home/user/Picture"
  31.  #DIR="/home/user/Documents/cultural-festivities/"
  32.  
  33.  # Command to Select a random jpg file from directory
  34.  PIC=$(find $DIR -type f -exec file {} \; | grep -o -P '^.+: \w+ image' | cut -d ':' -f 1 | shuf -n1)
  35.  
  36.  # Command to set Background Image
  37.  gsettings set org.cinnamon.desktop.background picture-uri "file:///$PIC"
  38.  
  39.  
  40.  
  41. else
  42.     echo "Could not find dbus session ID in user environment."
  43. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement