-
Notifications
You must be signed in to change notification settings - Fork 2
/
m2k_notify
executable file
·63 lines (56 loc) · 2.71 KB
/
m2k_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
#!/usr/bin/env bash
# m2k_notify sends a notification to the caller's desktop (currently only gnome).
#
# This file goes in $binpath
# This file is a modified version of librarian-notify-send.
# Which in turn is a modified version of alt-notify-send. It has
# been modified to send images with the notifications.
# An example of how it's used can be found in myth2kodi:
# https://github.com/stuart-knock/myth2kodi/blob/master/myth2kodi
#
#TODO: enable messages for DBUS using desktops other than Gnome. See 'pids='.
# KDE equiv is either kwin or kwin_x11.
#
#TODO: Categories, http://www.galago-project.org/specs/notification/0.9/x211.html
# "transfer" -- A generic file transfer or download notification that doesn't
# fit into any other category.
# ".complete" -- A file transfer or download complete notification.
# ".error" -- A file transfer or download error.
# "network" -- A generic network notification that doesn't fit into any other
# category.
# ".connected" -- A network connection notification, such as successful
# sign-on to a network service. This should not be
# confused with device.added for new network devices.
# ".disconnected" -- A network disconnected notification. This should not be
# confused with device.removed for disconnected network
# devices.
# ".error" A network-related or connection-related error.
user="$(whoami)"
pids="$(pgrep -u "$user" gnome-session)"
title="$1"
text="$2"
image="$3"
#notify-send fails without at least a title ('summary' in notify-send's terminology)
if [[ -z "$title" ]]; then
printf '%s\n' "ERROR: ${BASH_SOURCE[0]}: You need to give me a title" >&2
exit 1
fi
#notify-send can complain if there is no message, so fallback to reusing the title.
[[ -z "$text" ]] && text="$title"
#TODO: this isn't used by most/all desktops... consider just dropping it.
#NOTE: Ubuntu's Notify OSD and GNOME Shell both known to ignore this parameter.
if [[ -z "$timeout" ]]; then
#timeout=6000 #6 seconds
#timeout=60000 #1 minute
#timeout=180000 #3 minutes
timeout=1800000 #30 minutes
fi
for pid in $pids; do
#Avoid the warning about ignoring null-bytes in command substitution introduced in BASH 4.4
desktopenv="$( sed 's/\x0/\n/g' "/proc/$pid/environ" )"
# find DBUS session bus for this session
DBUS_SESSION_BUS_ADDRESS=$(grep DBUS_SESSION_BUS_ADDRESS <<<"$desktopenv" | sed -e 's/DBUS_SESSION_BUS_ADDRESS=//')
# send message to DBUS
DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS notify-send -u low -i "$image" "$title" "$text"
#DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS notify-send --app-name=Kodi -t $timeout -u low -i "$image" "$title" "$text"
done