Gsettings with cron

前端 未结 7 1842
北恋
北恋 2020-12-05 13:48

I wrote a bash script that changes the wallpaper (for GNOME3).

#!/bin/bash

# Wallpaper\'s directory.
dir=\"${HOME}/images/wallpapers/\"

# Random wallpaper.         


        
7条回答
  •  时光取名叫无心
    2020-12-05 14:29

    I found some solutions. When you export a variable DBUS_SESSION_BUS_ADDRESS contained in the file ~/.dbus/session-bus/*, dbus-launch does not tell more about the error. However, instead of wallpaper there are artefacts.

    Added code:

    sessionfile=`find "${HOME}/.dbus/session-bus/" -type f`
    export `grep "DBUS_SESSION_BUS_ADDRESS" "${sessionfile}" | sed '/^#/d'`
    

    Now the script looks like this:

    #!/bin/bash
    
    # TODO: At night only dark wallpapers.
    
    # Wallpaper's directory.
    dir="${HOME}/images/wallpapers/"
    
    # Weird, but necessary thing to run with cron.
    sessionfile=`find "${HOME}/.dbus/session-bus/" -type f`
    export `grep "DBUS_SESSION_BUS_ADDRESS" "${sessionfile}" | sed '/^#/d'`
    
    # Random wallpaper.
    wallpaper=`find "${dir}" -type f | shuf -n1`
    
    # Change wallpaper.
    # https://superuser.com/questions/298050/periodically-changing-wallpaper-under-gnome-3/298182#298182
    gsettings set org.gnome.desktop.background picture-options "spanned"
    gsettings set org.gnome.desktop.background picture-uri "file://${wallpaper}"
    

提交回复
热议问题