1

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
Zanna
  • 70,465
  • 1
    Please [edit] your question to include the output of pgrep -a gnome-session - it sounds like you have 2 gnome-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
  • The output is 829 1394. Right now I'm on windows running a virtual machine to test this. Could that be it? – Matías Cánepa May 22 '19 at 18:38
  • 1
    I was hoping the -a would give additional information about the origin of the processes – steeldriver May 22 '19 at 18:40
  • @steeldriver I'm sorry. I've missed the -a I will get back at you. In the meantime see my edit – Matías Cánepa May 22 '19 at 18:44
  • @steeldriver requested ouput: 829 /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:49
  • 1
    I assume you mistyped that (gm should be gdm)? if so, since the greeter likely runs as root, you could qualify the match using the current user PID=(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:08
  • both pgreg -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

0 Answers0