Advertisement
Guest User

Variety ~/.config/variety/scripts/set_wallpaper

a guest
Dec 18th, 2014
856
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 6.42 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # This script is run by Variety when a new wallpaper is set.
  4. # You can use bash, python or whatever suits you for the script.
  5. # Here you can put custom commands for setting the wallpaper on your specific desktop environment
  6. # or run commands like notify-send to notify you of the change, or you can
  7. # run commands that would theme your browser, login screen or whatever you desire.
  8. #
  9. # PARAMETERS:
  10. # $1: The first passed parameter is the absolute path to the wallpaper image to be set as wallpaper
  11. # (after effects, clock, etc. are applied).
  12. #
  13. # $2: The second passed parameter is "auto" when the wallpaper is changed automatically (i.e. regular change), "manual"
  14. # when the user has triggered the change or "refresh" when the change is triggered by a change in quotes, clock, etc.
  15. #
  16. # $3: The third passed parameter is the absolute path to the original wallpaper image (before effects, clock, etc.)
  17. #
  18. # EXAMPLE:
  19. # echo "$1" # /home/username/.config/variety/wallpaper/wallpaper-clock-fac0eef772f9b03bd9c0f82a79d72506.jpg
  20. # echo "$2" # auto
  21. # echo "$3" # /home/username/Pictures/Wallpapers/Nature/green-tunnel-1920x1080-wallpaper-861.jpg
  22.  
  23.  
  24. # Here you may apply some additional custom operations on the wallpaper before it is applied.
  25. # In the end put the path to the actual final wallpaper image file in the WP variable.
  26. # The default is to simply set WP=$1.
  27. WP=$1
  28.  
  29.  
  30. # Enlightenment
  31. # Needs Modules/System/DBus Extension loaded to work
  32. if [ "`echo $DESKTOP | grep Enlightenment`" ]; then
  33.  
  34.     OUTPUT_DIR="$HOME/.e/e/backgrounds"
  35.  
  36.     TEMPLATE='
  37.    images { image: "@IMAGE@" USER; }
  38.    collections {
  39.      group {
  40.      name: "e/desktop/background";
  41.      data { item: "style" "4"; item: "noanimation" "1"; }
  42.      max: @WIDTH@ @HEIGHT@;
  43.      parts {
  44.        part {
  45.        name: "bg";
  46.        mouse_events: 0;
  47.        description {
  48.          state: "default" 0.0;
  49.          aspect: @ASPECT@ @ASPECT@;
  50.          aspect_preference: NONE;
  51.          image { normal: "@IMAGE@"; scale_hint: STATIC; }
  52.        }
  53.        }
  54.      }
  55.      }
  56.    }
  57.    '
  58.  
  59.     OFILE="$OUTPUT_DIR/variety_wallpaper_$RANDOM"
  60.  
  61.     DIMENSION="$(identify -format "%w/%h" "$WP")"
  62.  
  63.     if [ ! -z "$DIMENSION" ]; then
  64.         WIDTH=$(echo $DIMENSION | cut -d/ -f1)
  65.         HEIGHT=$(echo $DIMENSION | cut -d/ -f2)
  66.         IMAGE="$(echo "$WP" | sed 's/[^[:alnum:]_-]/\\&/g')"
  67.  
  68.         if [ -z "$HEIGHT" -o "$HEIGHT" = "0" ]; then
  69.             ASPECT="0.0"
  70.         else
  71.             ASPECT=$(echo "scale=9; $DIMENSION" | bc)
  72.         fi
  73.     fi
  74.  
  75.     printf "%s" "$TEMPLATE" | \
  76.     sed "s/@ASPECT@/$ASPECT/g; s/@WIDTH@/$WIDTH/g; s/@HEIGHT@/$HEIGHT/g; s|@IMAGE@|$IMAGE|g" > "$OFILE.edc"
  77.     edje_cc "$OFILE.edc" "$OFILE.edj" 2>/dev/null
  78.     rm "$OFILE.edc"
  79.  
  80.     ## Get the current number of virtual desktops
  81.     desk_x_count=$(enlightenment_remote -desktops-get | awk '{print $1}')
  82.     desk_y_count=$(enlightenment_remote -desktops-get | awk '{print $2}')
  83.  
  84.     ## Set the wallpaper for each virtual desktop
  85.     for ((x=0; x<$desk_x_count; x++)); do
  86.         for ((y=0; y<$desk_y_count; y++)); do
  87.             # -desktop-bg-add OPT1 OPT2 OPT3 OPT4 OPT5 Add a desktop bg definition.
  88.             # OPT1 = ContainerNo OPT2 = ZoneNo OPT3 = Desk_x. OPT4 = Desk_y. OPT5 = bg file path
  89.             enlightenment_remote -desktop-bg-add 0 0 "$x" "$y" "$OFILE.edj";
  90.         done
  91.     done
  92.  
  93.     # Remove all Variety wallpapers, but the current one
  94.     find $OUTPUT_DIR -name "variety_wallpaper*.*" | grep -v "$OFILE.edj" | xargs rm
  95.     exit 0
  96. fi
  97.  
  98. # KDE - User will have to manually choose ~/Pictures/variety-wallpaper/ as a slideshow folder with a short iterval.
  99. # Afterwards, with the command below, Variety will just overwrite the single file there when changing the wallpaper
  100. # and KDE will refresh it
  101. if [ "`env | grep KDE_FULL_SESSION | tail -c +18`" == "true" ]; then
  102.     mkdir -p "$(xdg-user-dir PICTURES)/variety-wallpaper"
  103.     cp "$WP" "$(xdg-user-dir PICTURES)/variety-wallpaper/wallpaper-kde.jpg"
  104.     exit 0
  105. fi
  106.  
  107. # Cinnamon, for cases when it is detectable
  108. if [ "$XDG_CURRENT_DESKTOP" == "X-Cinnamon" ]; then
  109.     gsettings set org.cinnamon.background picture-uri "file://$WP" 2> /dev/null
  110.     if [ "`gsettings get org.cinnamon.background picture-options`" == "'none'" ]; then
  111.         gsettings set org.cinnamon.background picture-options 'zoom'
  112.     fi
  113.  
  114.     gsettings set org.cinnamon.desktop.background picture-uri "file://$WP" 2> /dev/null
  115.     if [ "`gsettings get org.cinnamon.desktop.background picture-options`" == "'none'" ]; then
  116.         gsettings set org.cinnamon.desktop.background picture-options 'zoom'
  117.     fi
  118.     exit 0
  119. fi
  120.  
  121. # Gnome 3, Unity
  122. gsettings set org.gnome.desktop.background picture-uri "file://$WP" 2> /dev/null
  123. gsettings set com.canonical.unity-greeter background "$WP"
  124. if [ "`gsettings get org.gnome.desktop.background picture-options`" == "'none'" ]; then
  125.     gsettings set org.gnome.desktop.background picture-options 'zoom'
  126. fi
  127.  
  128. # XFCE
  129. command -v xfconf-query >/dev/null 2>&1
  130. rc=$?
  131. if [[ $rc = 0 ]] ; then
  132.     for i in $(xfconf-query -c xfce4-desktop -p /backdrop -l|egrep -e "screen.*/monitor.*image-path$" -e "screen.*/monitor.*/last-image$"); do
  133.         xfconf-query -c xfce4-desktop -p $i -n -t string -s "" 2> /dev/null
  134.         xfconf-query -c xfce4-desktop -p $i -s "" 2> /dev/null
  135.         xfconf-query -c xfce4-desktop -p $i -s "$WP" 2> /dev/null
  136.     done
  137. fi
  138.  
  139. # LXDE/PCmanFM
  140. if [ "$XDG_CURRENT_DESKTOP" == "LXDE" ]; then
  141.     pcmanfm --set-wallpaper "$WP" 2> /dev/null
  142. fi
  143.  
  144. # Feh - commented, as it may cause problems with Nautilus, (see bug https://bugs.launchpad.net/variety/+bug/1047083)
  145. # feh --bg-scale "$WP" 2> /dev/null
  146.  
  147. # MATE after 1.6
  148. gsettings set org.mate.background picture-filename "$WP" 2> /dev/null
  149.  
  150. # MATE before 1.6
  151. mateconftool-2 -t string -s /desktop/mate/background/picture_filename "$WP" 2> /dev/null
  152.  
  153. # Cinnamon after 1.8, before 2.0
  154. gsettings set org.cinnamon.background picture-uri "file://$WP" 2> /dev/null
  155.  
  156. # Cinnamon after 2.0
  157. gsettings set org.cinnamon.desktop.background picture-uri "file://$WP" 2> /dev/null
  158.  
  159. # Gnome 2
  160. gconftool-2 -t string -s /desktop/gnome/background/picture_filename "$WP" 2> /dev/null
  161.  
  162. # Show a notification on wallpaper change (only when the change is automatic). Display the original filename, but the post-effects image.
  163. # name=$(echo "$3" | sed 's/\//\n/g'| tail -n 1)
  164. # if [ "$2" == "auto" ]; then notify-send --icon "$WP" "Wallpaper changed" "$name" ; fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement