I'm trying to change the desktop wallpaper via cron/bash. I've read a lot of questions and answers on this site an apparently I have to do something like
#!/bin/bash
MY_FILE_PATH=/home/$USER/file.jpg
PID=$(pgrep gnome-session)
export DBUS_SESSION_BUS_ADDRESS=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$PID/environ|cut -d= -f2-)
sleep 5
gsettings set org.gnome.desktop.background picture-uri file://$MY_FILE_PATH
But if run ./my_script.sh
I get
grep: /proc/X1: Is a directory
grep: X2/environ: No such file or directory
X1
and X2
are two different numbers and of course cron doesn't work
EDIT
If I manually set PID to one of the two numbers I get (on the line where export is made)
for X1 (829):
permission denied
for X2 (1394):
warning: command substitution: ignored null byte in input
pgrep -a gnome-session
- it sounds like you have 2gnome-session
processes running (which will make it tricky to figure out which one to apply the setting to) – steeldriver May 22 '19 at 18:33-a
would give additional information about the origin of the processes – steeldriver May 22 '19 at 18:40829 /usr/lib/gnome-session/gnome-session-binary --autostart /usr/share/gm/greeter/autostart 1394 /usr/lib/gnome-session/gnome-session-binary --session=ubuntu
– Matías Cánepa May 22 '19 at 18:49gm
should begdm
)? if so, since the greeter likely runs as root, you could qualify the match using the current userPID=(pgrep -u $USER gnome-session)
. Be aware that$USER
might not be set by default in crontabs - I assume you have addressed that already since you use it elsewhere in your script. – steeldriver May 23 '19 at 13:08pgreg -u $USER
and$USER
not avalilable in cron was what made it work! Post it like an answer if you like!! Thank you very much – Matías Cánepa May 23 '19 at 14:58