Advertisement
marioq

rotateImgDesktop bash rotazione delle immagini del desktop

Feb 15th, 2016
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 7.32 KB | None | 0 0
  1. #!/bin/bash
  2. # DA FINIRE DA FINIRE DA FINIRE DA FINIRE DA FINIRE DA FINIRE DA FINIRE DA FINIRE DA FINIRE DA FINIRE
  3. # DA FINIRE DA FINIRE DA FINIRE DA FINIRE DA FINIRE DA FINIRE DA FINIRE DA FINIRE DA FINIRE DA FINIRE
  4. # DA FINIRE DA FINIRE DA FINIRE DA FINIRE DA FINIRE DA FINIRE DA FINIRE DA FINIRE DA FINIRE DA FINIRE
  5.  
  6. # percorso completo del file .xml per impostare
  7. # la rotazione delle immagini sul desktop
  8. XML_WALLPAPER="$HOME/Immagini/wallpapers/mywallpaper.xml"
  9.  
  10. # folder da cui prendere le immagini .jpg .png
  11. IMG_FOLDER="/usr/share/backgrounds/"
  12.  
  13. # durata in secondi della visualizzazione dell'immagine
  14. IMG_DURATION="10,0"
  15.  
  16. # durata in secondi dell'effetto di transizione
  17. # da un'immagine a quella successiva
  18. IMG_TRANSITION="2,5"
  19.  
  20. ############################################################
  21. #                                                          #
  22. #      da qui in giù non dovrestri modificare niente       #
  23. #                                                          #
  24. ############################################################
  25.  
  26. if [ ! -d $IMG_FOLDER ]; then
  27.     echo -e "\t\t--------------------
  28.         la variabile \"\$IMG_FOLDER\" non ha
  29.         il valore corretto
  30. \t\t--------------------"
  31.     exit 1
  32. fi
  33.  
  34. # lista con ordine casuale delle immagini .jpg .png
  35. # IMG_LIST="`find $IMG_FOLDER \! -executable -readable -type f -iregex '\(.*\.png$\|.*\.jpg$\)' | sort -R | shuf | head -n10`"
  36. IMG_LIST="`find $IMG_FOLDER \! -executable -readable -type f -iregex '.*\.png$\|.*\.jpg$' | sort -R | shuf`"
  37. # IMG_LIST="`find $IMG_FOLDER \! -executable -readable -type f -iregex '.*\.xml$' | sort -R | shuf`"
  38.  
  39. # numero totale delle righe ed inizializzazione del contatore
  40. TOT_LINE=`echo "$IMG_LIST" | wc -l`
  41. COUNT=0
  42.  
  43. XML_HEADER(){
  44.     HEADER="<!--
  45. lista creata dallo script bash $0
  46. $TOT_LINE immagini dal folder $IMG_FOLDER
  47. -->
  48. <background>
  49.     <static>
  50.         <duration>$IMG_DURATION</duration>
  51.         <file>$1</file>
  52.     </static>
  53.     <transition>
  54.         <duration>$IMG_TRANSITION</duration>
  55.         <from>$1</from>"
  56.  
  57.     echo "$HEADER"
  58. }
  59.  
  60. XML_BODY(){
  61.     BODY="      <to>$1</to>
  62.     </transition>
  63.     <static>
  64.         <duration>$IMG_DURATION</duration>
  65.         <file>$1</file>
  66.     </static>
  67.     <transition>
  68.         <duration>$IMG_TRANSITION</duration>
  69.         <from>$1</from>"
  70.  
  71.     echo "$BODY"
  72. }
  73.  
  74. XML_FOOTER(){
  75.     FOOTER="        <to>$1</to>
  76.     </transition>
  77. </background>"
  78.  
  79.     echo "$FOOTER"
  80. }
  81.  
  82. for imgX in $IMG_LIST ; do
  83. let "COUNT=$COUNT+1"
  84.     if [ $COUNT -eq 1 ] ; then
  85.         XML_HEADER "$imgX" > $XML_WALLPAPER
  86.     fi
  87.  
  88.     if  [ $COUNT -lt $TOT_LINE -a $COUNT -gt 1 ] ; then
  89.         XML_BODY "$imgX" >> $XML_WALLPAPER
  90.     fi#!/bin/bash
  91. # DA FINIRE DA FINIRE DA FINIRE DA FINIRE DA FINIRE DA FINIRE DA FINIRE DA FINIRE DA FINIRE DA FINIRE
  92. # DA FINIRE DA FINIRE DA FINIRE DA FINIRE DA FINIRE DA FINIRE DA FINIRE DA FINIRE DA FINIRE DA FINIRE
  93. # DA FINIRE DA FINIRE DA FINIRE DA FINIRE DA FINIRE DA FINIRE DA FINIRE DA FINIRE DA FINIRE DA FINIRE
  94.  
  95. # percorso completo del file .xml per impostare
  96. # la rotazione delle immagini sul desktop
  97. XML_WALLPAPER="$HOME/Immagini/wallpapers/mywallpaper.xml"
  98.  
  99. # folder da cui prendere le immagini .jpg .png
  100. IMG_FOLDER="/usr/share/backgrounds/"
  101.  
  102. # durata in secondi della visualizzazione dell'immagine
  103. IMG_DURATION="10,0"
  104.  
  105. # durata in secondi dell'effetto di transizione
  106. # da un'immagine a quella successiva
  107. IMG_TRANSITION="2,5"
  108.  
  109. ############################################################
  110. #                                                          #
  111. #      da qui in giù non dovrestri modificare niente       #
  112. #                                                          #
  113. ############################################################
  114.  
  115. if [ ! -d $IMG_FOLDER ]; then
  116.     echo -e "\t\t--------------------
  117.         la variabile \"\$IMG_FOLDER\" non ha
  118.         il valore corretto
  119. \t\t--------------------"
  120.     exit 1
  121. fi
  122.  
  123. # lista con ordine casuale delle immagini .jpg .png
  124. # IMG_LIST="`find $IMG_FOLDER \! -executable -readable -type f -iregex '\(.*\.png$\|.*\.jpg$\)' | sort -R | shuf | head -n10`"
  125. IMG_LIST="`find $IMG_FOLDER \! -executable -readable -type f -iregex '.*\.png$\|.*\.jpg$' | sort -R | shuf`"
  126. # IMG_LIST="`find $IMG_FOLDER \! -executable -readable -type f -iregex '.*\.xml$' | sort -R | shuf`"
  127.  
  128. # numero totale delle righe ed inizializzazione del contatore
  129. TOT_LINE=`echo "$IMG_LIST" | wc -l`
  130. COUNT=0
  131.  
  132. XML_HEADER(){
  133.     HEADER="<!--
  134. lista creata dallo script bash $0
  135. $TOT_LINE immagini dal folder $IMG_FOLDER
  136. -->
  137. <background>
  138.     <static>
  139.         <duration>$IMG_DURATION</duration>
  140.         <file>$1</file>
  141.     </static>
  142.     <transition>
  143.         <duration>$IMG_TRANSITION</duration>
  144.         <from>$1</from>"
  145.  
  146.     echo "$HEADER"
  147. }
  148.  
  149. XML_BODY(){
  150.     BODY="      <to>$1</to>
  151.     </transition>
  152.     <static>
  153.         <duration>$IMG_DURATION</duration>
  154.         <file>$1</file>
  155.     </static>
  156.     <transition>
  157.         <duration>$IMG_TRANSITION</duration>
  158.         <from>$1</from>"
  159.  
  160.     echo "$BODY"
  161. }
  162.  
  163. XML_FOOTER(){
  164.     FOOTER="        <to>$1</to>
  165.     </transition>
  166. </background>"
  167.  
  168.     echo "$FOOTER"
  169. }
  170.  
  171. for imgX in $IMG_LIST ; do
  172. let "COUNT=$COUNT+1"
  173.     if [ $COUNT -eq 1 ] ; then
  174.         XML_HEADER "$imgX" > $XML_WALLPAPER
  175.     fi
  176.  
  177.     if  [ $COUNT -lt $TOT_LINE -a $COUNT -gt 1 ] ; then
  178.         XML_BODY "$imgX" >> $XML_WALLPAPER
  179.     fi
  180.  
  181.     if [ $COUNT -eq $TOT_LINE ] ; then
  182.         XML_FOOTER "$imgX" >> $XML_WALLPAPER
  183.     fi
  184. done
  185.  
  186. DW="dconf write"
  187.  
  188. custom_keybindings(){
  189. # Inserisco una combinazione di tasti per cambiare l'immagine del desktop
  190. # "$HOME/bin/changeImgDesktop" $HOME/bin/ è in $PATH e qui scrivo siolo il nome del file
  191.     $DW /org/gnome/settings-daemon/plugins/media-keys/custom-keybindings "['/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/my_custom/']"
  192.     $DW /org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/my_custom/command "'changeImgDesktop'"
  193.     $DW /org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/my_custom/name  "\"Cambia immagine di sfondo del Desktop\""
  194.     $DW /org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/my_custom/binding \"\<Alt\>b\"
  195.     echo -e "\tALT+b cambia immagine desktop"
  196. }
  197.  
  198. $DW /org/gnome/desktop/background/color-shading-type \'solid\'
  199. $DW /org/gnome/desktop/background/picture-options \'zoom\'
  200. $DW /org/gnome/desktop/background/picture-uri \'file://$XML_WALLPAPER\'
  201.  
  202. # echo $(readlink -m $(type -a $0 |awk '{print $3}'))
  203. echo `readlink -m $(type -a $0 | awk '{print $3}')`
  204.  
  205.  
  206.     if [ $COUNT -eq $TOT_LINE ] ; then
  207.         XML_FOOTER "$imgX" >> $XML_WALLPAPER
  208.     fi
  209. done
  210.  
  211. DW="dconf write"
  212.  
  213. custom_keybindings(){
  214. # Inserisco una combinazione di tasti per cambiare l'immagine del desktop
  215. # "$HOME/bin/changeImgDesktop" $HOME/bin/ è in $PATH e qui scrivo siolo il nome del file
  216.     $DW /org/gnome/settings-daemon/plugins/media-keys/custom-keybindings "['/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/my_custom/']"
  217.     $DW /org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/my_custom/command "'changeImgDesktop'"
  218.     $DW /org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/my_custom/name  "\"Cambia immagine di sfondo del Desktop\""
  219.     $DW /org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/my_custom/binding \"\<Alt\>b\"
  220.     echo -e "\tALT+b cambia immagine desktop"
  221. }
  222.  
  223. $DW /org/gnome/desktop/background/color-shading-type \'solid\'
  224. $DW /org/gnome/desktop/background/picture-options \'zoom\'
  225. $DW /org/gnome/desktop/background/picture-uri \'file://$XML_WALLPAPER\'
  226.  
  227. # echo $(readlink -m $(type -a $0 |awk '{print $3}'))
  228. echo `readlink -m $(type -a $0 | awk '{print $3}')`
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement