intro

swaywm is a window manager, and dunst is a notification daemon.

swaywm is rather minimal, with little to no defaults.

this means that for notifications, you have to launch a notification daemon like dunst. and if you want to use notifications in your scripts, you have to get your hands a little bit dirty…

how notification servers work

generally, notification servers in linux work through a program called dbus. dbus allows for system wide communication between programs, a sort of interface if you will…

how does this tie together

well, you need DBUS to send notifications that is for sure. and also you need the DBUS ID in-order to send notifications via a script, and you only get that ID through executing a script once your window manager launches, or through a command you invoke.

good thing is that the DBUS ID never changes midst session, and only when you launch the window manager.

so in your sway($XDG_CONFIG_HOME/sway/config) config, you could a little line like this:

exec "$DBUS_SESSION_BUS_ADDRESS" > /tmp/dbus

and then in each script you want to send a notification, you have to import it back like so:

export DBUS_SESSION_BUS_ADDRESS="$(cat /tmp/dbus)"
notify-send "henlo" # worke worke

also if you are root, you need to su into $USER. and sometimes maybe also export the environment variables $DISPLAY $WAYLAND_DISPLAY.

that is pretty much it, most problems will occur because $DBUS_SESSION_BUS_ADDRESS is either invalid or misspelled.