Thursday, April 11, 2024

reminder to take a break - using cron

Wanted to create a pop-up message or reminder (and was later requested an audio reminder) for N to take periodic breaks from the computer. Since his usage was mostly passive, workrave did not work for this purpose - workrave's timer only progresses when the keyboard or mouse are active.

 Looking for solutions, reminder apps on Mint/Ubuntu seemed to have only flatpak versions which I did not want to install.

Finally thought it would be simpler to use cron.

But, to pop up messages on the screen with cron, we need some special handling.
https://unix.stackexchange.com/questions/307772/pop-up-a-message-on-the-gui-from-cron
https://unix.stackexchange.com/questions/111188/using-notify-send-with-cron

And for audio, we would need another line to be added to the script. Working script - 

#!/bin/bash
export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
export DISPLAY=:0
export XDG_RUNTIME_DIR=/run/user/1000
# this last line above is for sound to work
notify-send -u critical "this is the reminder to take a walk"
# the -u critical is supposed to show over full screen apps, but doesn't always work
/usr/bin/mpg123 /home/username/Downloads/Walk.mp3 > /dev/null 2>&1

For help with setting up cron, cron.help is useful. Eg.

*/30 * * * * /home/username/walkremind.sh

for every half an hour.

For getting the environment variables' values, used

printenv

And for installing notify-send

sudo apt install libnotify-bin






No comments:

Post a Comment