0

How can I issue a shell command in my terminal that will alert me with a notification once a given time has passed?

To make it a bit more specific, some things I am looking for are:

  • I only need one off alerts, not recurring. For example, systemd timers have such a functionality, but having to create a whole systemd unit and timer every time (and then having to delete it) would be too impractical.
  • A simple CLI, so I can do something like remindme "3 hours" "see if thing x has finished yet" and not have to do too much complicated shell magic. Failing that, if it's at least something that can be wrapped in a script, that would be preferable.
  • It's enough if the notification is just a string meant for me to read.
  • Cross-platform: It should at least work on Linux and Mac.
  • The notifications should not require me to leave my shell open.
  • If the notification happens through a GUI, it should at least support Xorg and Macs. I assume this will be something like a balloon popup or dialog box; this should support different DEs and not force me to use Gnome for example.
  • If the notification happens through a terminal, it would be nice if it worked both in the TTY (without Xorg) and in a terminal emulator under X.
  • The notification doesn't have to be right on the dot, for example if I set it to 1 hour, and it actually ends up notifying after 63 mins, that's okay.
  • I shouldn't have to run a command to check notifications, since I will inevitably forget to do so. So for example taskwarrior supports various timed tasks, but I wouldn't see those until I run task next.
  • It shouldn't overshoot my time delay by too much. For example, if I tried to add a checkreminders command to my bashrc it might actually be a long time before I launch a new shell and see the notifications. The same goes for things like alias ls=checkreminders && ls.
  • It should not depend on an external service (eg. webapp or my gmail account). For example, Slack has a reminder bot but I don't want to run Slack all the time on every computer just so I can use the notifications.
  • I would prefer if the dependencies were minimal, and I didn't have to install a whole bunch of gigantic programs on every computer where I wish to use this. Smaller CLI programs that are widely available in package managers are okay, if they come with most Linux distros by default, even better.
4
  • 1
    Use the at command and zenity? Both come in a package by the given names from your distro's index. See here for details and instructions on Zenity, and see man at after having installed it.
    – Izzy
    Aug 25, 2021 at 21:29
  • @Izzy Seems like it might work, I'll check it out. Why did you post as a comment, rather than an answer?
    – Haterind
    Aug 27, 2021 at 21:56
  • Because I wasn't sure if it fully meets your requirements. I'll convert it to an answer when you confirmed :)
    – Izzy
    Aug 27, 2021 at 23:58
  • 1
    @Izzy Got it, no worries!
    – Haterind
    Aug 30, 2021 at 22:08

1 Answer 1

0

Usage: remindme -t "3m 1s" -m "I have to do homework"
Time can be simply number meaning second, or have suffix s, m, h or d. See man page for GNU sleep. For macOS you need to convert time into seconds or write a function to do so.

Solution 1: Using wall. Works on Linux, graphically and non-graphically, should work on macOS, atleast non-graphically.

#!/bin/bash
while getopts "t:m:" optname; do
case $optname in
t)
time=${OPTARG}
;;
m)
message=${OPTARG}
;;
esac
done
coproc (sleep $time && wall $message)

Solution 2.1: Desktop notifiaction for Linux and Windows, require notify-send provided by libnotify

#!/bin/bash
while getopts "t:m:" optname; do
case $optname in
t)
time=${OPTARG}
;;
m)
message=${OPTARG}
;;
esac
done
coproc (sleep $time && notify-send -a Reminder "$message")

Solution 2.2: Desktop notification for macOS. Not tested.

#!/bin/bash
while getopts "t:m:" optname; do
case $optname in
t)
time=${OPTARG}
;;
m)
message=${OPTARG}
;;
esac
done
coproc (sleep $time && osascript -e 'display notification "$message" with title "Remainder"')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.