I'm trying to make my random-wallpaper script run every 15 minutes using cron and pywal to change the terminal color pallet. This is my script:
#!/bin/bash
export PATH="$PATH:$HOME/.local/bin/"
files=($HOME/Imagens/wallpapers/*)
image="$(printf "%s\n" "${files[RANDOM % ${#files[@]}]}")"
wal -i $image
And this is the cron line i'm using:
*/15 * * * * DISPLAY=:0 ~/.scripts/random-wallpaper
This works fine when i run it from the terminal and also when using cron on i3wm, but when i switched to gnome it just changes the colors of the terminal as it is suposed to using the new wallpaper as reference, but the wallpaper doesn't change. I tried using DISPLAY=:0.0, using . instead of it, and nothing works.
I need some help figuring out what the issue is.
I came across this post when I was searching for my solution to this. My initial try with wal did something similar to me in awesomewm, where the the terminal colors would change but the background wouldn't. This is what I ultimately did to fix it, though I'm sure it's not the ideal solution. Note that I'm not certain this will work for gnome, as I am bouncing between awesomewm and xmonad. But, you might be able to tweak my approach to suit your needs. I did this with the following cron line:
* * * * * /bin/wal -a 95 -i "$HOME/wallpaper/" -n; DISPLAY=:0 feh --bg-scale "$(< "${HOME}/.cache/wal/wal")"
The important part to note here is the -n flag for wal suppresses wal setting the background (not that that was your issue), but the file path still changes in the .cache/wal/wal file. Also, note that I just pass wal the directory, and it picks a random image from the directory. I then use feh to set the background, but needed to use DISPLAY=:0 to pass the environment variable. I don't know if feh will work to set the background for gnome, but in the very least using wal in this way might simplify your script and perhaps thinking about using something else besides wal to set the background may help. Perhaps you can use gsettings to set the background in gnome, but an initial look tells me others seem to have trouble setting backgrounds with gsettings and cron jobs, but I can't really speak to this as I'm not entirely familiar with how you can set the background in gnome from the terminal (besides running wal from the terminal). Perhaps this post on S.O. will assist you further for doing this in gnome if the above approach using feh doesn't.