2

Good day ... working as a developer made me change my theme regularly, day and night, i have 2 themes "Light & Dark". i made a bash script to change the gtk-theme and shell-theme from cli, it works fine. However, when I issued the script via crontab, it fails to work and reports failure connecting to display and Dbus issues

here is my crontab

  * *   *   *   *    DISPLAY=:0.0 /home/newton/scripts/dark-mode.sh

and here is my script

#!/bin/bash
export DISPLAY=:0.0
export WAYLAND_DISPLAY=wayland-0

/usr/bin/gsettings set org.gnome.desktop.interface gtk-theme 'Vimix-Dark-Laptop-Ruby' 
/usr/bin/gsettings set org.gnome.shell.extensions.user-theme name 'Vimix-Dark-Laptop-Ruby' 

Please help me solve this issue, i think it will be helpful to lots of people. Regards Mohammed Gritli

2 Answers2

1

Thank you @Kristopher Ives

I've tried that answer before, but the PID comes as a directory and the DBUS_SESSION_BUS_ADDRESS becomes empty again.

I've got a way around with a friend by adding the following on the top of the crontab file:

DISPLAY=:0
WAYLAND_DISPLAY=wayland-0
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus

i grabbed the variable from my env output

afterwards, everything worked fine, i also managed to change my "vscode theme" via "sed" command by replacing the theme name along

here is my full files "crontab -e"

#changing theme based on day-light 
DISPLAY=:0
GNOME_SHELL_SESSION_MODE=ubuntu
USER=newton
DESKTOP_SESSION=ubuntu-wayland
WAYLAND_DISPLAY=wayland-0
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
XAUTHORITY=/home/newton/.Xauthority

# m   h  dom mon dow   command
  */5   19-05   *   *    *   DISPLAY=:0.0 /home/newton/scripts/dark-mode.sh
  */5 06-18   *   *    *   DISPLAY=:0.0 /home/newton/scripts/light-mode.sh

"content of dark-mode.sh"

#!/bin/bash

/usr/bin/gsettings set org.gnome.desktop.interface gtk-theme 'Vimix-Dark-Laptop-Ruby' 
/usr/bin/gsettings set org.gnome.shell.extensions.user-theme name 'Vimix-Dark-Laptop-Ruby' 
sed -i 's/Atom One Light/Ubuntu Style Theme/g' /home/newton/.config/Code/User/settings.json

"content of light-mode.sh"

#!/bin/bash

/usr/bin/gsettings set org.gnome.desktop.interface gtk-theme 'Vimix-Light-Laptop-Ruby' 
/usr/bin/gsettings set org.gnome.shell.extensions.user-theme name 'Vimix-Light-Laptop-Ruby' 
sed -i 's/Ubuntu Style Theme/Atom One Light/g' /home/newton/.config/Code/User/settings.json

Regards Mohammed Gritli

0

See this answer about changing a desktop background and how to connect to DBUS_SESSION_BUS_ADDRESS

Background not changing using gsettings from cron