How to get a custom desktop notification every third hour?

I was wondering if it is possible to get a custom desktop notification every third hour from the computer starts and how do I do that?

create a systemd user timer that runs in that interval. You want a monotonic timer with OnBootSec .

Start with that timer a systemd user service that runs notify-send with the options you want. notify-send usually works on all DE's but depending on your DE there might be a better DE specific command.

https://wiki.archlinux.org/index.php/Systemd/Timers
https://www.freedesktop.org/software/systemd/man/systemd.timer.html

User timers and services are stored in ~/.config/systemd/user/ .

4 Likes

Look up notify-send from then you could easily write a simple bash script.

#!/usr/bin/env python

import time
import subprocess

while True:
    time.sleep(180)
    subprocess.run('notify-send "Hello !!!"', shell=True, check=True)
2 Likes

Another way is the cron.
Create script "notifymeevery3rdhour" something like:

export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus &&
notify-send "your message"

add to crontab:

0 */3 * * * $HOME/bin/notifymeevery3rdhour

cron can be cranky about using notify-send. you can do some extra work to make sure notify-send knows where to send it, or you can be lazy like me and use xmessage instead.

2 Likes

Okay so I solved this by using xircons python script and making a systemd service which starts that script on startup. Thanks again guys for all the help. Cheers!

I also modified the script a little and added sound to the notification using python-vlc. So as you can see in this script. I wanted to have a notification that reminded me to drink something every third hour.

#!/usr/bin/env python

import vlc
import time
import subprocess

sound_file = vlc.MediaPlayer("/path/to/sound.mp3")

while True:
    time.sleep(10800)
    subprocess.run('notify-send "Make sure you stay hydrated. Right now you should at least have consumed a glass of '
                   'water or any other type of beverage"', shell=True, check=True)
    sound_file.play()
    time.sleep(6)
    sound_file.stop()
1 Like

Hmmmm :beers: :wine_glass: :smiley:

2 Likes

I need no reminders :wink:
Cheers!
[Glad you got it working ... and you learned some python, scripting, desktop-notifications, and systemd along the way. I like seeing things like this happen.]

1 Like

I already knew a bit of this. But I learned a bit more. Also it feels so nice when you've made it yourself. It's like making your own food it taste different when you make yourself, usually in a good way. :wink:

You never met my mother. :stuck_out_tongue_winking_eye:

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.

Forum kindly sponsored by