forked from SethMilliken/binfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotify
executable file
·156 lines (149 loc) · 5.5 KB
/
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/bin/sh
#
# Script to facilitate posting Growl notifications.
# Customization allows for using different themes for different message sources.
# Can also act as a more versatile replacement for growlnotify.
#
# After posting a notification with this script, go to the "Applications" tab of
# the Growl system preference pane to customize it.
#
# Author: Seth Milliken <[email protected]>
# Date: 2011-01-14 13:45:46 PST
# Version: 0.1
#
## Usage:
if [ $# == 0 ]; then
echo 'NOTIFICATION_SCRIPT=${HOME}'"/bin/$(basename $0)"
echo '${NOTIFICATION_SCRIPT} $(basename $0) "false" "${MESSAGE}" "${HEADER}" ${IDENTIFIER} ${APP_ICON}'
echo
echo "# Use the lines above to use $(basename $0) in a bash script. (n.b. in vim \":r !$(basename $0)\", then normal vipd this para.)"
echo '# Lines below for commandline use.'
echo "# $(basename $0) \"Header\" -m \"Message\""
echo "# $(basename $0) \"Header\" \"true\" \"Message\" # for sticky"
echo
exit 0
fi
## Arg Name Assignment:
SCRIPT=$1
STICKY=$2
MESSAGE=$(echo "${3}" | sed -e 's/"/\\"/g')
HEADER=$4
IDENTIFIER=$5
APP_ICON=$6
## AppleScript Notification:
osascript << END
property script_name: "${SCRIPT}"
property isSticky: "${STICKY}"
property message: "${MESSAGE}"
property header: "${HEADER}"
property identifier: "${IDENTIFIER}"
property app_icon: "${APP_ICON}"
on run
my dispatch_message()
end run
on dispatch_message()
set defaults to \
{ \
notification: "Default Notification", \
icon: app_icon, \
header: header, \
script_name: script_name, \
id: identifier, \
priority: 0 \
}
if script_name is "tester" then
set parameters to \
{ \
notification: "Test Notification", \
header: "test message" \
} & defaults
else if script_name is "synswitch" then
set parameters to \
{ \
notification: "Default Notification" \
} & defaults
else if script_name is "currentstatus" then
set parameters to \
{ \
notification: "Tasks Notification", \
icon: "Tasks.app" \
} & defaults
else if script_name is "transit_alert" then
set parameters to \
{ \
notification: "Transit Notification", \
icon: "Network Utility.app" \
} & defaults
else if script_name is "playpause" then
set parameters to \
{ \
notification: "iTunes Notification", \
icon: "iTunes", \
id: "itunes_notification" \
} & defaults
else if script_name is "grun" then
set parameters to \
{ \
notification: "Shell Notification" \
} & defaults
else if script_name is "syn_local" or script_name is "syn_remote" then
set parameters to \
{ \
notification: "Switch Notification", \
app: "Synergy Notifications", \
icon: "Divvy", \
header: "synergy", \
id: "synergy_notification", \
priority: -2 \
} & defaults
else
set parameters to defaults
end if
my send_notification(parameters)
end dispatch_message
on send_notification(parameters)
tell application "Growl"
set the all_notifications to {notification of parameters}
set the enabled_notifications to {notification of parameters}
set the notification_name to (notification of parameters)
try
set the app_name to (app of parameters)
on error
set app_name to (notification of parameters) & "s"
end try
set message_priority to (priority of parameters)
if message_priority is "" then
set message_priority to 0
end if
set message_header to (header of parameters)
if message_header is "" then
set message_header to (script_name of parameters)
end if
set message_id to (id of parameters)
if message_id is "" then
set message_id to script_name & "_notification"
end if
set app_icon to (icon of parameters)
if app_icon is "" then
set app_icon to "Terminal.app"
end if
if isSticky is "" then
set isSticky to "false"
end if
register as \
application app_name \
all notifications all_notifications \
default notifications enabled_notifications \
icon of application app_icon
notify with \
name notification_name \
title message_header \
description message \
application name app_name \
identifier message_id \
priority message_priority \
sticky isSticky
end tell
end send_notification
END
# vim:ts=2:sts=2:ft=applescript