Automatically change your wallpaper using cron
In my voidlinux I have installed:
sudo xbps-install -Sy cronie
And then I have started the service:
doas ln -s /etc/sv/crond /var/service/
NOTE: opendoas is an option for those who do not like sudo :)
My crontab:
NOTE: We need to take care of the variables, specially DISPLAY, XAUTHORITY and DBUS_SESSION_BUS_ADDRESS.
SHELL=/usr/bin/bash
PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
MAILTO=""
DISPLAY=:0
XAUTHORITY=/home/sergio/.Xauthority
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
# for debugging
# * * * * * /usr/bin/wal -qi "/home/sergio/img/backgrounds" >> /tmp/wal_cron.log 2>&1
# change at 5 minute interval
*/5 * * * * /usr/bin/wal -qi "/home/sergio/img/backgrounds" >/dev/null 2>&1
*/20 8-20 * * * /home/sergio/.dotfiles/bin/drink-water.sh
Drink watter reminder with cron
I have found this article teaching us how to use cron to remind us of drinking water.
in my case I have this script:
#!/usr/bin/env bash
# File: ~/.dotfiles/bin/drink-water.sh
# Last Change: Sun, Nov 2025/11/23 - 19:07:12
# Author: Sérgio Araújo
# Purpose: Notificar o usuário para se hidratar
# tags: [water, cron, dunst, notify-send]
# vim: set ts=2 sw=2 et fenc=utf-8 ft=sh nospell:
# Descobre o endereço do D-Bus da sessão atual
BUS=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$(pgrep -u "$USER" -x dunst | head -n1)/environ | sed 's/DBUS_SESSION_BUS_ADDRESS=//')
# Você pode usar outro processo que roda na sua sessão, como:
# pgrep -u "$USER" -x sway
# pgrep -u "$USER" -x Xorg
# pgrep -u "$USER" -x xfce4-session
# pgrep -u "$USER" -x openbox
# etc.
# O dunst é ótimo porque sempre está rodando no ambiente gráfico.
export DBUS_SESSION_BUS_ADDRESS="$BUS"
export DISPLAY=:0
export XAUTHORITY="/home/sergio/.Xauthority"
notify-send -i "/home/sergio/.dotfiles/dunst/icons/drink-water.svg" \
"Água" "$(date '+%H:%M') - Hidrate-se"
Top comments (0)