-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalert
More file actions
executable file
·98 lines (79 loc) · 1.73 KB
/
Copy pathalert
File metadata and controls
executable file
·98 lines (79 loc) · 1.73 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/bin/bash
__track_usage "$(basename "$0")"
# Usage:
# alert -t "Title" -b "Body" -d 3 -s
# Where:
# -t = Alert title
# -b = Alert body
# -d = Delay in seconds
# -D = Delay, using the format of timeDiff / date -v adjustment
# -s = (Optional) Say the alert in addition to displaying a notification
# SETINGS
SPEAK=0
DELAY=""
TITLE=""
BODY=""
OPTIND=1
while getopts "st:xb:xd:xD:x" opt; do
case "$opt" in
s) SPEAK=1
;;
t) TITLE="$OPTARG"
;;
d) DELAY="$OPTARG"
;;
D) DELAY=$(timeDiff "$OPTARG")
;;
b) BODY="$OPTARG"
;;
esac
done
shift $((OPTIND-1))
[ "$1" = "--" ] && shift
if [ -n "$@" ]; then
TITLE=" "
BODY="$@"
if [ -z "$DELAY" ]; then
read -p "Delay (in seconds)?" DELAY
fi
fi
if [ -z "$TITLE" ]; then
echo "Message title not provided: -t argument is required."
exit 1
fi
if [ -z "$BODY" ]; then
echo "Message body not provided: -b argument is required."
exit 1
fi
if [ -z "$DELAY" ]; then
echo "Time delay not provided: -d argument is required."
exit 1
fi
isNumber() { [ "$1" -eq "$1" ] 2>/dev/null; }
if ! isNumber "$DELAY"; then
echo "Provided delay, "$DELAY" is not a valid number";
exit 1
fi
speakNotification() {
local title="$1"
local body="$2"
local content="Alert! $title. $body."
say "$content"
}
displayNotification() {
local title="$1"
local body="$2"
local script='display notification "'$body'" with title "'$title'"'
osascript -e "$script"
}
doNotification() {
displayNotification "$TITLE" "$BODY"
if (($SPEAK == 1)); then
speakNotification "$TITLE" "$BODY"
fi
}
echo "In $DELAY seconds, will send the alert:"
echo "$TITLE :"
echo "$BODY"
{ sleep "$DELAY"; doNotification; } &
disown