web-dev-qa-db-fra.com

Comment puis-je obtenir un papier peint pour chaque jour de la semaine?

Alors j'ai une idée. Pour me faire mieux connaître le jour de la semaine, je souhaite un fond d’écran personnalisé pour chaque jour. Mais je ne sais pas comment y parvenir.

Existe-t-il un logiciel pouvant le faire pour moi? Sinon, est-ce que quelqu'un pourrait aider à mettre en place un script qui puisse changer l'arrière-plan chaque jour?

5
Lars Erik Grambo

Créez un script comme cet exemple appelé dailywallpaper.sh:

#!/bin/bash

# Variables explained:
# [wallpaperpath]....The directory with your wallpapers.
# [background].......The wallpaper. For the current "Week" day make a symbolic
#                    link to the desired image.  Name the line the a number 
#                    between 1-7 with a dash and the name without extension.
#                    (ie. ln -s image.png 3-daily for the thrird day of the
#                    week)
# [default]..........The default wallpaper to set if the file matching the
#                     current day isn't found.

DBUS=$(ps aux | egrep "/gnome-session/.*\s--session=" | awk '{print $2}')
export $(strings /proc/$DBUS/environ | egrep DBUS_SESSION_BUS_ADDRESS)
day=$(date +"%u")

wallpaperpath="/home/userid/backgrounds/"
background="$day-daily"
default="manhattan-wallpaper-2.jpg"
# Default when the specified file isn't found.

newwallpaper="$wallpaperpath$default"
[[ -f "$wallpaperpath$background" ]] && newwallpaper="$wallpaperpath$background"

gsettings set org.gnome.desktop.background picture-uri "file://${newwallpaper}"

L'utilisation du script est expliquée dans les commentaires du script. Vous pouvez configurer le script pour qu'il s'exécute via crontab.

Exemple de saisie dans Crontab:

# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
0 0 * * * /home/myaccount/bin/dailywallpaper.sh

L'application Startup Applications est nécessaire si vous n'êtes pas connecté à minuit. L'application de démarrage procédera au changement lorsque vous vous connecterez. Vous pouvez trouver l'application Applications de démarrage dans le tableau de bord Ubuntu: (Tableau de bord Ubuntu -> Startup Applications).

The Startup Applications app

L'entrée crontab définit la variable d'arrière-plan si vous êtes connecté. L'application Startup Applications définit la variable si vous n'étiez pas connecté à minuit lors de l'exécution du cron.

En utilisant les deux, le fond d'écran du jour correct sera toujours affiché.

4
L. D. James

Je voudrais utiliser le papier peint cyclisme:

enter image description here

Ensuite, j'utiliserais conky pour afficher le jour de la semaine:

enter image description here

Depuis ce site Web: https://ubuntuforums.org/showthread.php?t=281865&page=2325&p=13554728#post13554728

Et cette image: https://ubuntuforums.org/attachment.php?attachmentid=26401

Il est très facile d'avoir Conky pour afficher MONDAY en grosses lettres majuscules. Consultez le site Web, trouvez un script qui vous plaira et modifiez-le en fonction de vos besoins.

1
WinEunuuchs2Unix

Paramétrer le papier peint de cron

La définition du papier peint à partir de cron nécessite la définition de gsettings. Puisque cron fonctionne avec un ensemble très limité de variables d’environnement, vous devrez définir une variable spéciale, appelée:

DBUS_SESSION_BUS_ADDRESS

Non le (à quoi vous pouvez vous attendre) DISPLAY -variable.
Voir aussi ici comment faire cela.

Alternativement

Alternativement, vous pouvez utiliser le script simple ci-dessous. Au démarrage, le script définit le papier peint correspondant, puis il ne reste qu’à attendre minuit pour changer le papier peint. Puis encore dormir jusqu'à la prochaine minuit et ainsi de suite.

Le scénario

import time
import os
import subprocess

picsdir = "/home/jacob/Bureaublad/pics"
images = sorted([os.path.join(picsdir, pic) for pic in os.listdir(picsdir)])

def calc_sleep():
    secdata = time.strftime("%H %M %S").split()
    seconds = (int(secdata[0])*3600)+(int(secdata[1])*60)+(int(secdata[2]))
    # calculate the sleep time until next midnight
    return 86400+1-seconds

while True:
    # weekday
    day = int(time.strftime("%w"))
    # the corresponding image from the set folder
    image = images[day-1]
    # set the image from gsettings
    command = ["gsettings", "set", "org.gnome.desktop.background",
               "picture-uri", "file://"+image]
    subprocess.check_call(command)
    # calculate the time to sleep until next midnight
    wait = calc_sleep()
    time.sleep(wait)

Comment utiliser

  1. Créer un répertoire avec sept fonds d'écran
  2. Copiez le script dans un fichier vide, enregistrez-le sous le nom wallswitch.py
  3. Dans la tête du script, définissez le chemin d'accès aux fonds d'écran
  4. Testez le script:

    python3 /path/to/wallswitch.py
    

    Le papier peint correspondant au jour de la semaine doit être défini.

  5. Si tout fonctionne correctement, ajoutez-le à Applications de démarrage: Dash> Applications de démarrage> Ajouter. Ajoutez la commande:

    /bin/bash -c "sleep 10 && python3 /path/to/wallswitch.py"
    
1
Jacob Vlijm