4

I made a simple bash script that changes the wallpaper for a random picture from my wallpapers directory using pcmanfm. It's something like that:

#!/bin/bash

pcmanfm -w "$(find /home/likewise-open/MAPS/lucas.cardeal/Pictures/Wallpapers -type f | shuf -n1)"

I want that automatically, so u put the script on crontab. But it has no effect when its called by crontab. What's wrong with my script? How can I fix it?

Thanks

ProgramFOX
  • 6,131
  • 11
  • 45
  • 51
lscardeal
  • 69
  • 6
  • Try supplying the complete path to `pcmanfm` in the script. – devnull Oct 29 '13 at 14:01
  • "has no effect when its called by crontab." -- how does it fail? `cron` can be configured to send the output of stderr to a mail address, or you could redirect stdout/stderr to a file when it's invoked. – Brian Cain Oct 29 '13 at 14:02
  • I tried to supply the script with the full path of pcmanfm and it's still not working. I checked the strerr, but there is no error at all. The script runs, but it dont change the wallpapers. I tried to add a line {> test.txt /home/lscardeal/Desktop}, and the file was created. There's something wrong with how I call pcmanfm command, i guess Thank you for the replies – lscardeal Oct 29 '13 at 14:37

1 Answers1

5

That script will give you a X11 authorization error when is set as cron job. To prevent this, just add export DISPLAY=:0 and export XAUTHORITY=/home/username/.Xauthority (change username with your user name) in your script:

#!/bin/bash

export DISPLAY=:0
export XAUTHORITY=/home/username/.Xauthority   #change `username` with your user name

pcmanfm -w "$(find /home/likewise-open/MAPS/lucas.cardeal/Pictures/Wallpapers -type f | shuf -n1)"

ADDENDUM: An update caused the above script to break in Lubuntu 16.04 and above. See this stackoverflow answer https://stackoverflow.com/a/46259031/5895207 for the additional environment variable that needs to be specified in the script.

Radu Rădeanu
  • 2,642
  • 2
  • 26
  • 43
  • This worked for me (RasPi Buster) after exporting `XDG_RUNTIME_DIR` as mentioned in the link provided in the answer. Thanks! – S3DEV Oct 22 '19 at 20:46