Skip to content

Instantly share code, notes, and snippets.

@criztovyl
Last active January 14, 2017 22:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save criztovyl/7f9628d5b32286f1658d to your computer and use it in GitHub Desktop.
Save criztovyl/7f9628d5b32286f1658d to your computer and use it in GitHub Desktop.
Hacky-Hacky notify-send hack for sending from cron(tab).
#!/bin/bash
# Hacky-Hacky notify-send hack for sending from cron(tab).
# Copyright (C) 2016 Christoph criztovyl Schulz
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
notify-send-remote()
{
#Args: user summary message
user=$1
summary=$2
message=$3
mfile="messageto"$user$RANDOM
# The .dbus_session_bus_address file is should contain the current dbus session bus address in following form:
# "export DBUS_SESSION_BUS_ADDRESS=[session bus address]"
# Best way to achieve this is to add the following script to your startup applications:
# echo "export DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS" > ~/.dbus_session_bus_address
# You may use the z-dbus-session-export files in this gist. (copy the .desktop file to ~/.config/autostart and the .sh file to ~/.local/opt/dbus_session_export.sh)
cd /home/$user &&
echo ". .dbus_session_bus_address && notify-send \"$summary\" \"$message\"" > $mfile &&
chown $user:$user $mfile && chmod +x $mfile &&
sudo -u $user "/bin/bash" "./$mfile" &&
rm $mfile
}
notify-send-remote "$1" "$2" "$3"
[Desktop Entry]
Comment=
Terminal=false
Name=DBUS Session Export
Exec=/opt/dbus-session-export.sh
Type=Application
#!/bin/bash
umask 277
file="$HOME/.dbus_session_bus_address"
[ -f $file ] && rm -f $file
[ $DBUS_SESSION_BUS_ADDRESS ] && echo "export DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS" > $file || echo "No dbus session"
#!/bin/bash
case $1 in
"install")
ln -s z-dbus-session-export-autostart.desktop /etc/xdg/autostart/
mkdir -p /opt/
ln -s z-dbus-session-export.sh /opt/dbus-session-export.sh
chmod a+x /opt/dbus-session-export.sh
;;
"uninstall"|"remove")
rm -f /etc/xdg/autostart/z-dbus-session-export.sh
rm -f /opt/dbus-session-export.sh
;;
*|"help")
echo "Usage: $0 install|remove"
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment