Created
April 5, 2019 12:35
-
-
Save TopperBG/c235aa3f465c9c98b0c2a46a7682d793 to your computer and use it in GitHub Desktop.
notify-send-as-root.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# This script shows how to send a libnotify message | |
# to a specific user. | |
# | |
# It looks for a process that was started by the user and is connected to dbus. | |
# process to determine DBUS_SESSION_BUS_ADDRESS | |
USER_DBUS_PROCESS_NAME="gconfd-2" | |
USER="makubi" | |
NOTIFY_SEND_BIN="/usr/bin/notify-send" | |
TITLE="title" | |
MESSAGE="notify message" | |
# get pid of user dbus process | |
DBUS_PID=`ps ax | grep $USER_DBUS_PROCESS_NAME | grep -v grep | awk '{ print $1 }'` | |
# get DBUS_SESSION_BUS_ADDRESS variable | |
DBUS_SESSION=`grep -z DBUS_SESSION_BUS_ADDRESS /proc/$DBUS_PID/environ | sed -e s/DBUS_SESSION_BUS_ADDRESS=//` | |
# send notify | |
DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION su -c "$NOTIFY_SEND_BIN \"$TITLE\" \"$MESSAGE\"" $USER |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment