-
Notifications
You must be signed in to change notification settings - Fork 0
/
notify.sh
executable file
·77 lines (70 loc) · 2.46 KB
/
notify.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
73
74
75
76
77
#!/bin/bash
# updated for terminal-notifier v2.0.0: https://github.com/julienXX/terminal-notifier
account=$(/usr/bin/id -un)
process="Process Name" # exchange for actual process name depending on your script
icon_loc="/.VolumeIcon.icns" # exchange for actual path to the icon image file
# notify function
notify () {
if [[ "$tn_status" == "osa" ]] ; then
osascript &>/dev/null << EOT
tell application "System Events"
display notification "$2" with title "$process [" & "$account" & "]" subtitle "$1"
end tell
EOT
elif [[ "$tn_status" == "tn-app-new" ]] || [[ "$tn_status" == "tn-app-old" ]] ; then
"$tn_loc/Contents/MacOS/terminal-notifier" \
-title "$process [$account]" \
-subtitle "$1" \
-message "$2" \
-appIcon "$icon_loc" \
>/dev/null
elif [[ "$tn_status" == "tn-cli" ]] ; then
"$tn" \
-title "$process [$account]" \
-subtitle "$1" \
-message "$2" \
-appIcon "$icon_loc" \
>/dev/null
fi
}
# look for terminal-notifier
tn=$(which terminal-notifier 2>/dev/null)
if [[ "$tn" == "" ]] || [[ "$tn" == *"not found" ]] ; then
tn_loc=$(mdfind "kMDItemCFBundleIdentifier == 'fr.julienxx.oss.terminal-notifier'" 2>/dev/null | awk 'NR==1')
if [[ "$tn_loc" == "" ]] ; then
tn_loc=$(mdfind "kMDItemCFBundleIdentifier == 'nl.superalloy.oss.terminal-notifier'" 2>/dev/null | awk 'NR==1')
if [[ "$tn_loc" == "" ]] ; then
tn_status="osa"
else
tn_status="tn-app-old"
fi
else
tn_status="tn-app-new"
fi
else
tn_vers=$("$tn" -help | head -1 | awk -F'[()]' '{print $2}' | awk -F. '{print $1"."$2}')
if (( $(echo "$tn_vers >= 1.8" | bc -l) )) && (( $(echo "$tn_vers < 2.0" | bc -l) )) ; then
tn_status="tn-cli"
else
tn_loc=$(mdfind "kMDItemCFBundleIdentifier == 'fr.julienxx.oss.terminal-notifier'" 2>/dev/null | awk 'NR==1')
if [[ "$tn_loc" == "" ]] ; then
tn_loc=$(mdfind "kMDItemCFBundleIdentifier == 'nl.superalloy.oss.terminal-notifier'" 2>/dev/null | awk 'NR==1')
if [[ "$tn_loc" == "" ]] ; then
tn_status="osa"
else
tn_status="tn-app-old"
fi
else
tn_status="tn-app-new"
fi
fi
fi
# notify: exchange subtitle & message text for the actual strings (using test notification)
notify "Test notification" "Status: $tn_status"
# print variables (only for testing)
echo "\$PATH: $tn"
echo "Version: $tn_vers"
echo ".app executable location: $tn_loc"
echo "Status: $tn_status"
# test notification directly from $PATH
terminal-notifier -title "$process [$account]" -subtitle "Test notification" -message "$tn" -appIcon "$icon_loc"