Skip to content

04 Automating the theme switching (Configuring Cron)

Mrcuve0 edited this page Sep 5, 2020 · 2 revisions

LightHouse: Automation!

Introduction

As for now (alpha releases), LightHouse automates only the theme application but cannot launch itself at a certain hour of the day. To do that we leverage the cron service. In this wiki page we will follow the official cron Arch Wiki as additional and detailed source of information/

Installing cron

Follow the Installation section of the Arch Wiki to install and manage cron. To easily manage cron in the following steps, I highly suggest you to install kcron (also called Task Scheduler) to easily handle the configurations files we are going to write. To do that, if you are using pacman as package manager, simply issue the following command:

sudo pacman -S kcron

On Debian-based distros you'll probably need to issue the following command (I didn't try it but should be ok):

sudo apt install kcron

Configuring our cron tasks

In order to painlessly configure cron (which can be quite tricky, just Google "cron doesn't work" and you'll see) please launch kcron (or look for the program Task Scheduler, they are the same thing).

In the following list you can see the 2 task I scheduled in order to launch LightHouse twice (once in the morning in order to apply the Light theme and once in the evening to apply the Dark theme) There's also a third Task, the first one in the list that I used to check if cron executes the command properly.

TaskList

Here's an example of the single task-related time configuration:

TaskTime

To help you, here's an example of commands:

/bin/python3 /home/$USER/folder/path/to/LightHouse.py -p Aritim-Dark_DEV -g Aritim-Dark-GTK -w /home/sem/Pictures/Wallpapers/Aritim-Dark_DEV/sky_NIGHT2.png -k Aritim-Dark_DEV

/bin/python3 /home/$USER/folder/path/to/LightHouse.py -p Aritim-Light_DEV -g Aritim-Light-GTK -w /home/sem/Pictures/Wallpapers/Aritim-Light_DEV/clouds2_DAY.jpg -k Aritim-Light_DEV

Configuring cron environment variables

As a last step, to correctly configure the actions executed by cron we need to pass to it some environment variables. You can find additional infos in the related Arch Wiki section.

  1. Open a terminal and run the following commands:

echo $PATH

then:

echo $DISPLAY

and finally:

echo $DBUS_SESSION_BUS_ADDRESS

  1. Now, on Task Schedule main window, add these 3 environment variables (PATH, DISPLAY and DBUS_SESSION_BUS_ADDRESS) and their related values (which are diplayed everytime you issue the terminal commands)

Here's an example of what you should achieve at the end of the process: TaskVar

  1. Finally, Apply all the changes and close Task Scheduler.

If everything has been set up correctly, cron should launch LightHouse which in turn will switch automatically your themes.