From ec96e09021599d7a0dfc114a09cafaf496ede5e6 Mon Sep 17 00:00:00 2001 From: Sanchayan Maity Date: Thu, 6 Oct 2016 15:41:22 +0530 Subject: [PATCH] mutt: Fix desktop mail notification To send desktop notification from a background script running as root (replace X_user and X_userid with the user and userid running X respectively): sudo -u X_user DISPLAY=:0 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/ X_userid/bus notify-send 'Hello world!' 'This is an example notification.' Taken from https://wiki.archlinux.org/index.php/Desktop_notifications --- mutt/mailnotify.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/mutt/mailnotify.sh b/mutt/mailnotify.sh index 00bd365..a97b913 100755 --- a/mutt/mailnotify.sh +++ b/mutt/mailnotify.sh @@ -5,13 +5,16 @@ let stefan_mail_count=`ls /home/sanchayan/Mail/Sanchayan/Stefan/new/|wc -l` let sanchayan_linux=`ls /home/sanchayan/Mail/Sanchayan/Linux\ Kernel/new/|wc -l` if (("$toradex_mail_count" > 0)); then - /usr/bin/notify-send "You have $toradex_mail_count new mails in Toradex" --icon=dialog-information; + sudo -u sanchayan DISPLAY=:0 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus notify-send "You have +$toradex_mail_count new mails in Toradex" fi if (("$stefan_mail_count" > 0)); then - /usr/bin/notify-send "You have $stefan_mail_count new mails in Stefan inbox" --icon=dialog-information; + sudo -u sanchayan DISPLAY=:0 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus notify-send "You have +$stefan_mail_count new mails in Stefan inbox" fi if (("$sanchayan_linux" > 0)); then - /usr/bin/notify-send "You have $sanchayan_linux new mails in Linux Kernel inbox" --icon=dialog-information; + sudo -u sanchayan DISPLAY=:0 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus notify-send "You have +$sanchayan_linux new mails in Linux Kernel inbox" fi