0

So, I'm trying to change my theme from a light to a dark version in the evening, and vica versa in the morning. However, Gsettings doesn't work from Cron, and the solutions posted here and here don't seem to work, neither do those posted in the comments below them.

This is the script Cron is executing:

#!/bin/bash

#Export DBUS_SESSION_BUS_ADDRESS environment variable
PID=$(pgrep -o gnome-shell)
export DBUS_SESSION_BUS_ADDRESS=$(grep -z DBUS_SESSION_BUS_ADDRESS/proc/$PID/environ|cut -d= -f2-)

#Change theme
gsettings set org.gnome.desktop.interface gtk-theme 'Arc-Dark'
gsettings set org.gnome.shell.extensions.user-theme name 'Arc-Dark'

And this is the error I'm getting in dead.letter (Crons' way of logging errors):

grep: /proc/1098/environ: Permission denied

(process:28536): dconf-WARNING **: failed to commit changes to dconf: The given address is empty


grep: /proc/1098/environ: Permission denied

(process:28811): dconf-WARNING **: failed to commit changes to dconf: The given address is empty

I know I can use sudo -u to run the script, but I'd rather not use the root cron.

4
  • I am not sure I am the specialist on the subject, but anyone who' d be able to answer would probably ask: does it work when run from the command line (not cron)? Dec 2, 2015 at 18:16
  • It could be due to environ permission, it should be readable only for root (-r-------- 1 test test 0 Dec 2 19:38 environ)
    – Lety
    Dec 2, 2015 at 18:41
  • @JacobVlijm yes, the script works from command line, and cron executes the script correctly. If I set it to write 'lol test' to a text file, it does. The problem lies within Cron (that somehow can't call gsettings correctly).
    – user478138
    Dec 3, 2015 at 3:31
  • Because the script is executed within cron's context, perhaps replacing gsettings with what $(which gsettings)resolves to ? (I doubt this will make a difference, but might be worth a try).
    – Cbhihe
    Dec 3, 2015 at 15:04

1 Answer 1

0

I was having a similar issue running a dconf command from cron. In my case I added dbus-launch to the beginning of my command as well as adding a variable DISPLAY=:0 to the crontab file.

my crontab looks like this: DISPLAY=:0 0 6 * * * dbus-launch /path/to/my/dconf-script