I am monitoring my computer screen time usage and I often find myself running uptime --pretty and I would like to find out a better way. My goal is to to wrap my work up within 2 hours of sitting at the computer. My ideas are to have a program launch at first boot login, then at the 1.5 hr or 2 hr mark set off a notification on my notification tray so that I may save my work and logout/poweroff. I know how to set programs to launch at startup via startup applications however clueless how to fire notifications. I am using 20.04 on Gnome.
Asked
Active
Viewed 849 times
4
-
"boot" is usually not the same as "login". Creating a notification depends on the programming language you use. – Marco Jun 12 '22 at 11:57
-
@Marco yes I believe I should use the term `login` instead of `boot`. How do I make a notification and which language has the best support? – Weezy Jun 12 '22 at 12:06
-
1I was going to suggest a [systemd timer unit](https://www.freedesktop.org/software/systemd/man/systemd.timer.html), but interestingly that approach has two limitations that make it unsuitable for this usage (logging out early does not guarantee the timer gets stopped, and it will not always get started on subsequent logins after the first login). – Austin Hemmelgarn Jun 12 '22 at 22:46
1 Answers
6
Use the
sleepcommand withh(hours) like so:sleep 2hWith the
notify-sendcommand like so:notify-send "Please wrap up your work."Both in a
shcommand stringsh -c '...'like so:sh -c 'sleep 2h; notify-send "Please wrap up your work."'Then, add a new startup application and paste the above
shcommand string in the command field like so:Then, save it.
Next time you login and thereafter, you will be notified after two hours of login.
Raffa
- 24,905
- 3
- 35
- 79
-
Amazing. This looks like just the thing I need. However I am concerned about `sleep` using CPU cycles. Does it? If yes, is there a way to call `notify-send` at a specific time ? – Weezy Jun 12 '22 at 16:57
-
2@Weezy No, it doesn't …. Actually, it’s the most CPU efficient method in your use case … please see https://askubuntu.com/a/524918 and https://stackoverflow.com/a/51279647 – Raffa Jun 12 '22 at 17:08
