Contenu | Rechercher | Menus

Annonce

Si vous avez des soucis pour rester connecté, déconnectez-vous puis reconnectez-vous depuis ce lien en cochant la case
Me connecter automatiquement lors de mes prochaines visites.

À propos de l'équipe du forum.

#1 Le 22/07/2011, à 14:04

popol06

Script pour fond d'écran diaporama

Salut,

Je pense que ça a été fait refait..... mais ayant découvert zenity il y a peu (et que ma femme n'aime pas la ligne de commande... !), j'ai fait un script shell / zenity, qui génère un xml, qui permet d'avoir un fond d'écran diaporama.
le script permet:
- de choisir plusieurs images (message d' erreur si l'on en sélectionne qu'une).
- de choisir la durée d'affichage (message d' erreur si on met autre chose que des chiffres).
- de choisir un nom pour son diaporama (s'il existe déjà, on peut soit ressaisir un nouveau nom, soit l'écraser).
- les xml crées vont dans /home/utilisateur/diaporamaxml
- la conf est directement injectée dans /home/utilisateur/.gnome2/background.xml ("base de données" des fonds d'écran dans la fenêtre de propriétés de l'apparence)
- lance les propriétés de l'apparence avec le diaporama prêt à l'emploi.

Testé uniquement sur Natty, si les chemins sont pareil dans les autres versions, ça doit fonctionner aussi.

#!/bin/bash
p=0
place="/home/"$USER"/Images/"
if test ! -f /home/"$USER"/.gnome2/backgrounds.xml; then
zenity --info --text="Le script ne trouve pas /home/"$USER"/.gnome2/backgrounds.xml \nCe script a été testé sur Ubuntu 11.04. \nPeut-être avez-vous une version plus ancienne ? \nLe script va maintenant s'arrêter"
exit; fi
    
killall /usr/bin/gnome-appearance-properties 2>/dev/null
wait

if test ! -d /home/"$USER"/diaporamaxml/; then
    mkdir /home/"$USER"/diaporamaxml; fi

zenity --info --text="Ce script permet de sélectionner des images, \nafin de créer un fond d'écran sous forme de diaporama"
if (( $? == 1)); then exit; fi
while [ "$p" -eq "0" ]
do
FILE=$(zenity --file-selection --filename="$place" --multiple --title="Sélectionnez les images...")'|'
if (( $? == 1)); then exit; fi
l=$(echo "$FILE" | grep -o "|" | wc -l)
m=$(( l - 1 ))
if [ "$m" -eq "0" ]
    then zenity --error --text="Il faut sélectionner au moins 2 images...!"
         if (( $? == 1)); then exit; fi
else
    while [ "$p" -eq "0" ]
    do
        duree=$(zenity --entry --text="Durée d'affichage des images \nen minutes :")
        if (( $? == 1)); then exit; fi
        if echo "$duree" | egrep -q '^[0-9]+$'; then 
            duree2=$(($duree * 60))
            while [ $p -eq "0" ]
                do
                    nom=$(zenity --entry --text="Nom du diaporama")
                    if (( $? == 1)); then exit; fi
                    if test -f /home/"$USER"/diaporamaxml/"$nom".xml; then    
                    zenity --question --text="Attention ce diaporama existe déjà ! \nVoulez vous l'écraser ? \n\nSi vous répondez 'non' vous pourrez saisir un autre nom."; fi
                    if (( $? == 0 )); then break; fi
            done
            
            
            echo "<background>" > /home/"$USER"/diaporamaxml/"$nom".xml
            echo "  <starttime>" >> /home/"$USER"/diaporamaxml/"$nom".xml
            echo "    <year>2009</year>" >> /home/"$USER"/diaporamaxml/"$nom".xml
            echo "    <month>08</month>" >> /home/"$USER"/diaporamaxml/"$nom".xml
            echo "    <day>04</day>" >> /home/"$USER"/diaporamaxml/"$nom".xml
            echo "    <hour>00</hour>" >> /home/"$USER"/diaporamaxml/"$nom".xml
            echo "    <minute>00</minute>" >> /home/"$USER"/diaporamaxml/"$nom".xml
            echo "    <second>00</second>" >> /home/"$USER"/diaporamaxml/"$nom".xml
            echo "  </starttime>" >> /home/"$USER"/diaporamaxml/"$nom".xml 
            while [ $m -ne 0 ]
                do
                    fileok=$(echo "$FILE" | cut -f"$l" -d'|')
                    fileok2=$(echo "$FILE" | cut -f"$m" -d'|')
                    echo "  <static>"  >> /home/"$USER"/diaporamaxml/"$nom".xml
                    echo "    <duration>"$duree2".0</duration>" >> /home/"$USER"/diaporamaxml/"$nom".xml
                    echo "    <file>$fileok</file>" >> /home/"$USER"/diaporamaxml/"$nom".xml
                    echo "  </static>" >> /home/"$USER"/diaporamaxml/"$nom".xml
                    echo "  <transition>" >> /home/"$USER"/diaporamaxml/"$nom".xml
                    echo "    <duration>5.0</duration>" >> /home/"$USER"/diaporamaxml/"$nom".xml
                    echo "    <from>$fileok</from>" >> /home/"$USER"/diaporamaxml/"$nom".xml
                    echo "    <to>$fileok2</to>" >> /home/"$USER"/diaporamaxml/"$nom".xml
                    echo "  </transition>" >> /home/"$USER"/diaporamaxml/"$nom".xml
                    l=$(( l-1 ))
                    m=$(( m-1 ))
        
            done
            echo "  <static>" >> /home/"$USER"/diaporamaxml/"$nom".xml
            echo "    <duration>"$duree2".0</duration>" >> /home/"$USER"/diaporamaxml/"$nom".xml
            echo "    <file>$fileok2</file>" >> /home/"$USER"/diaporamaxml/"$nom".xml
            echo "  </static>" >> /home/"$USER"/diaporamaxml/"$nom".xml
            echo "</background>" >> /home/"$USER"/diaporamaxml/"$nom".xml
            
            sed -i '$d' /home/$USER/.gnome2/backgrounds.xml
            echo '  <wallpaper deleted="false">' >> /home/$USER/.gnome2/backgrounds.xml
            echo "    <name>"$nom"</name>" >> /home/$USER/.gnome2/backgrounds.xml
            echo "    <filename>/home/"$USER"/diaporamaxml/"$nom".xml</filename>" >> /home/$USER/.gnome2/backgrounds.xml
            echo "    <options>zoom</options>" >> /home/$USER/.gnome2/backgrounds.xml
            echo "    <shade_type>solid</shade_type>" >> /home/$USER/.gnome2/backgrounds.xml
            echo "    <pcolor>#000000000000</pcolor>" >> /home/$USER/.gnome2/backgrounds.xml
            echo "    <scolor>#000000000000</scolor>" >> /home/$USER/.gnome2/backgrounds.xml
            echo "  </wallpaper>"  >> /home/$USER/.gnome2/backgrounds.xml
            echo " </wallpapers>"  >> /home/$USER/.gnome2/backgrounds.xml
            zenity --info --text="Le diaporama '"$nom"' à été crée \nVous pouvez à présent l'utiliser dans les propriétés de l'apparence..."
            /usr/bin/gnome-appearance-properties -p background
            exit;
        
        else 
            zenity --error --text="Veuillez saisir un nombre...!";
            if (( $? == 1)); then exit; fi
        fi

    done
fi
done

Bon week end

Hors ligne

#2 Le 22/07/2011, à 15:47

FRUiT

Re : Script pour fond d'écran diaporama

Et bien, gnome ne propose pas nativement de diaporama sur le bureau comme kde ?.?? big_smile


Neon Suite by FRUiT (kde4.6) [url]http://[Merci de relire les règles]/yzm7cee[/url]
"Pour la carotte, le lapin est la plus parfaite incarnation du mal" (R. Sheckley)
clean

Hors ligne

#3 Le 22/07/2011, à 15:56

FRUiT

Re : Script pour fond d'écran diaporama

Au lieu de faire :

            echo "<background>" > /home/"$USER"/diaporamaxml/"$nom".xml
            echo "  <starttime>" >> /home/"$USER"/diaporamaxml/"$nom".xml
            echo "    <year>2009</year>" >> /home/"$USER"/diaporamaxml/"$nom".xml

Tu peux faire :

            {
                echo "<background>"
                echo "  <starttime>"
                echo "    <year>2009</year>"
                # etc...
            } >> /home/"$USER"/diaporamaxml/"$nom".xml


Au lieu de faire :

l=$(echo "$FILE" | grep -o "|" | wc -l)
m=$(( l - 1 ))

Tu peux faire :

m=$(($(echo "$FILE" | grep -o "|" | wc -l)-1))

Neon Suite by FRUiT (kde4.6) [url]http://[Merci de relire les règles]/yzm7cee[/url]
"Pour la carotte, le lapin est la plus parfaite incarnation du mal" (R. Sheckley)
clean

Hors ligne

#4 Le 22/07/2011, à 21:06

popol06

Re : Script pour fond d'écran diaporama

il y a bien le diaporama supporté, mais pas de logiciels natif qui permettent de générer ce xml......
Et merci pour tes conseils....

Hors ligne

#5 Le 25/07/2011, à 00:25

HP

Re : Script pour fond d'écran diaporama

FRUiT a écrit :

Au lieu de faire :

            echo "<background>" > /home/"$USER"/diaporamaxml/"$nom".xml
            echo "  <starttime>" >> /home/"$USER"/diaporamaxml/"$nom".xml
            echo "    <year>2009</year>" >> /home/"$USER"/diaporamaxml/"$nom".xml

Tu peux faire :

            {
                echo "<background>"
                echo "  <starttime>"
                echo "    <year>2009</year>"
                # etc...
            } >> /home/"$USER"/diaporamaxml/"$nom".xml

Oui, ou sinon : http://en.wikipedia.org/wiki/Here_document#Unix_Shells


cat /dev/urandom >/dev/null 2>&1 #github

Hors ligne