-
Notifications
You must be signed in to change notification settings - Fork 0
/
reminder.sh
executable file
·72 lines (56 loc) · 1.79 KB
/
reminder.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
which python3 > /dev/null || { echo "python3 not installed." ; exit 1 ; }
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
usage () {
cat << EOF
DESCRIPTION:
The purpose of this tool is to display popup notifications at specific times.
SYNOPSIS:
reminder add <time> <message> [<url>]
reminder list
reminder stop <pid>
reminder -h
ACTIONS:
add Add a new reminder
list Show scheduled reminders
stop Stop the reminder with the given process id.
OPTIONS:
<time> The time at which the popup notice is to be open in 24h format (HH:MM), e.g. 15:25.
<message> The message to be displayed in the popup notice.
<url> The URL to be opened. On Linux the URL will open automatically with the default browser. On MacOS the URL will be rendered as link in the popup notification.
<pid> The operating system process id of the scheduled reminder.
-h Show this message.
EOF
}
ACTION=$1
if [[ -z "${ACTION}" || "${ACTION}" = "-h" ]]; then
usage
exit 0
fi
if [[ "${ACTION}" == "add" ]]; then
REMINDER_TIME=$2
REMINDER_TEXT=$3
REMINDER_URL=$4
REMINDER_TIME=$(${SCRIPT_DIR}/lib/to_HH:SS.py ${REMINDER_TIME})
if [[ -z "${REMINDER_TEXT}" ]]; then
REMINDER_TEXT=" "
fi
if [[ -n "${REMINDER_URL}" ]]; then
if [[ ! "${REMINDER_URL}" = http* ]]; then
echo "ERROR: Reminder URL '${REMINDER_URL}' has an invalid format." >&2
exit 1
fi
fi
nohup ${SCRIPT_DIR}/schedule_notification.sh -t ${REMINDER_TIME} -m "${REMINDER_TEXT}" -u "${REMINDER_URL}" > /dev/null 2>&1 &
exit 0
fi
if [[ "${ACTION}" == "list" ]]; then
${SCRIPT_DIR}/lib/list_notifications.py
exit 0
fi
if [[ "${ACTION}" == "stop" ]]; then
kill -9 $2
exit 0
fi
usage
exit 1