Notify when network is up?

Hi all,

I’m trying to receive a notification (in Gnome) when the network is up.

I created and set +x /etc/NetworkManager/dispatcher.d/notify-network-up.sh

with this content:

#!/bin/bash
if [ "$2" = "up" ]; then
    notify-send "Network Up" "The network is now connected."
fi
exit 0

and then I enabled NetworkManager-dispatcher.service.
But it doesn’t seem to work when I disconnect and reconnect. Any idea why?

EDIT: just noticed the NM dispatcher status says “Cannot autolaunch D-Bus without X11 $DISPLAY”. I tried adding DISPLAY=:0.0 to my script but it doesn’t do anything?

Try:

export DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/$UID/bus"

I seem to remember encountering this a long time ago.

1 Like

It still doesn’t seem to work, now it says:

nm-dispatcher: Could not connect: No such file or directory

Ok, I had to modify it a few times but now it works. Thanks :slight_smile:

#!/bin/bash

USER="me"

export DISPLAY=:0
export XDG_RUNTIME_DIR="/run/user/$(id -u)"
export DBUS_SESSION_BUS_ADDRESS="unix:path=${XDG_RUNTIME_DIR}/bus"

if [ "$2" = "up" ]; then
    systemd-run --user --machine=${USER}@.host --user notify-send "Network Up" "The network is now connected."
fi

exit 0