Scheduling notifications on Ubuntu in a geeky way
Several days ago I tried to find out a way to schedule notifications on my Ubuntu, mostly for myself. The reason why I bothered about it is because I wanted to get rid of all the distractions namely email notifications, messenger, etc. so that I can verify updates - e.g. new emails without breaking concentration and actually staying in the flow.
Luckily I’m using Ubuntu as an OS for my work. And this wonderful OS has everything what we need to set up notifications without the need to install extra software, if you geeky enough :)
In order to show notification on Ubuntu you may use wide variety of the existing command line tools, e.g. zenity, notify-send, etc. I picked notify-send as it generates nice auto-dismissable popup notifications, e.g.
notify-send "Check Email: `date`"
For scheduling I used cron.
But the straightforward way of using X-windows-bound things like notify-send won’t work being used by cron directly. This is because cron tasks are executed from the special, cron user. But if this user have sufficient priveleges to read your .Xauthority it is not a problem (and usually it does, and it does on Ubuntu if not specially reconfigured).
So I ended up with the special notification launcher, like this one:
# !/bin/bash
export DISPLAY=:0.0;
# $HOME/.Xauthority
export XAUTHORITY=/home/alex/.Xauthority
/usr/bin/notify-send "Check Email `date`"
I saved this script under the name /home/alex/notify_email
Then I added cron task that was able to launch my script. You may manage your cron tasks by using crontab utility, e.g. list existing task - sudo crontab -l
and edit cron task by invoking sudo crontab -e
.
My configuration looked as follows:
# m h dom mon dow command
40 * * * 1,2,3,4,5 /home/alex/notify_email
This means - invoke notify_email
script once per hour, in each *:40 minutes, each working day (remember - the week starts with Sunday that comes under the number 0).
That’s it. Have fun!