Gsettings with cron

前端 未结 7 1843
北恋
北恋 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:14

    Also see this solution that work for me: https://unix.stackexchange.com/questions/111188/using-notify-send-with-cron#answer-111190 :

    You need to set the DBUS_SESSION_BUS_ADDRESS variable. By default cron does not have access to the variable. To remedy this put the following script somewhere and call it when the user logs in, for example using awesome and the run_once function mentioned on the wiki. Any method will do, since it does not harm if the function is called more often than required.

    #!/bin/sh
    
    touch $HOME/.dbus/Xdbus
    chmod 600 $HOME/.dbus/Xdbus
    env | grep DBUS_SESSION_BUS_ADDRESS > $HOME/.dbus/Xdbus
    echo 'export DBUS_SESSION_BUS_ADDRESS' >> $HOME/.dbus/Xdbus
    
    exit 0
    

    This creates a file containing the required Dbus evironment variable. Then in the script called by cron you import the variable by sourcing the script:

    if [ -r "$HOME/.dbus/Xdbus" ]; then
      . "$HOME/.dbus/Xdbus"
    fi
    

提交回复
热议问题