Sunday, December 12, 2010

Add reminder on Unix terminal

   echo "DISPLAY=':0' zenity --warning --text 'Tea time'" | at 1756 March 11

You can also make it a bash function as I have done

>> remind () {
    echo "DISPLAY=':0' zenity --warning --text '$@'" | at $1
}

Usage:
>> remind 17:56 Tea Time

>> remind 17:56today Tea Time

>> remind 17:56tomorrow Tea Time

>> remind now+30min Take break

The time formats that "at" command accepts are
At allows fairly complex time specifications, extending the POSIX.2 standard. It accepts times of the form HH:MM to run a job at a spe‐ cific time of day. (If that time is already past, the next day is assumed.) You may also specify midnight, noon, or teatime (4pm) and you can have a time-of-day suffixed with AM or PM for running in the morning or the evening. You can also say what day the job will be run, by giving a date in the form month-name day with an optional year, or giving a date of the form MMDD[CC]YY, MM/DD/[CC]YY, DD.MM.[CC]YY or [CC]YY-MM-DD. The specification of a date must follow the specifica‐ tion of the time of day. You can also give times like now + count time-units, where the time-units can be minutes, hours, days, or weeks and you can tell at to run the job today by suffixing the time with today and to run the job tomorrow by suffixing the time with tomorrow. For example, to run a job at 4pm three days from now, you would do at 4pm + 3 days, to run a job at 10:00am on July 31, you would do at 10am Jul 31 and to run a job at 1am tomorrow, you would do at 1am tomorrow. The definition of the time specification can be found in /usr/share/doc/at/timespec.
What if you want to be reminded every weekday at 6:17 PM to go to gym? For that you can use crontab
> > echo "17 18 1-5 * * DISPLAY=':0' zenity --warning --text 'Tea time'" | crontab -
The first 5 space separated words provide when the script should run in the format "minute hour weekday day-of-month month", followed by the script to execute. Google crontab to learn more.

1 comment: