4

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.

Raffa
  • 32,237
Weezy
  • 451
  • "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
  • 1
    I was going to suggest a systemd timer unit, 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 Answers1

6
  • Use the sleep command with h(hours) like so:

    sleep 2h
    
  • With the notify-send command like so:

    notify-send "Please wrap up your work."
    
  • Both in a sh command string sh -c '...' like so:

    sh -c 'sleep 2h; notify-send "Please wrap up your work."'
    
  • Then, add a new startup application and paste the above sh command string in the command field like so:

    enter image description here

  • Then, save it.

  • Next time you login and thereafter, you will be notified after two hours of login.

Raffa
  • 32,237
  • 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