-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwt-notify
executable file
·109 lines (95 loc) · 2.21 KB
/
wt-notify
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
99
100
101
102
103
104
105
106
107
108
109
#!/bin/sh
# Copyright (C) 2014 Francois Gouget
#
# Displays a notification message to the user.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
name0=`basename "$0"`
error()
{
echo "$name0:error:" "$@" >&2
}
#
# Command line processing
#
opt_msg=""
usage=""
while [ $# -gt 0 ]
do
arg="$1"
shift
if [ "$arg" = "--help" -o "$arg" = "-h" -o "$arg" = "-?" ]
then
usage=0
break
elif [ -z "$opt_msg" ]
then
opt_msg="$arg"
else
error "unknown option '$arg'"
usage=2
break
fi
done
if [ -z "$usage" ]
then
if [ -z "$opt_msg" ]
then
error "you must provide the text of the notification"
usage=2
fi
fi
if [ "$usage" = "0" ]
then
echo "Usage: $name0 [--help] MESSAGE"
echo
echo "Displays a notification to the user."
echo
echo "Where:"
echo " MESSAGE This is the text of the notification."
echo " --help, -h Shows this help message."
exit 0
elif [ -n "$usage" ]
then
error "try '$name0 --help' for more information"
exit $usage
fi
#
# Display the notification
#
echo "$opt_msg"
if type osascript >/dev/null 2>&1
then
# This does not work on Snow Leopard and lower :-(
exec osascript <<EOF
tell application "System Events"
display notification "$opt_msg"
end tell
EOF
elif type notify-send >/dev/null 2>&1
then
if [ -z "$DISPLAY" ]
then
DISPLAY=":0.0"
export DISPLAY
fi
exec notify-send "$opt_msg"
else
if [ -z "$DISPLAY" ]
then
DISPLAY=":0.0"
export DISPLAY
fi
exec zenity --notification --window-icon info --text "$opt_msg" 2>/dev/null &
fi