I have scheduled a job in crontab to change the desktop background randomly, every minute in Lubuntu, using the following script:
#!/bin/bash
export DISPLAY=:0
PHOTOS_PATH=~/Pictures/wallpapers/
number_of_photos=$(ls $PHOTOS_PATH | wc -l)
# generates a random number in range 1 through $number_of_photos
random=$( shuf -i 1-$number_of_photos -n 1 )
# returns the name of the file at line number $random of `ls` output
photo_file=$(ls $PHOTOS_PATH | head --lines=$random | tail --lines=1)
pcmanfm --set-wallpaper=$PHOTOS_PATH/$photo_file
exit 0
But every minute, the following error message appears on the screen:
The problem is with the line of the script that issues command pcmanfm
, since (according to my experiments) this message appears exactly at the execution of that command. I've also run this script from inside tty1, and it changed my desktop background successfully, with no error. How can I overcome this problem with crontab?
$(pgrep gnome-session -n -U $UID)
with$(pgrep lxsession -n -U $UID)
(source). Another related topics: [1], [2], [3]. – pa4080 Mar 26 '18 at 12:42export XDG_RUNTIME_DIR=/run/user/1000
in my script solves the problem. – Hedayat Mahdipour Mar 26 '18 at 14:31