2

I need to send a desktop notification to the user from some shell scripts using notify-send, so i found this answer and it's working under X11 without any problem, so i tried to add Wayland support to the script by using $WAYLAND_DISPLAY to make it work in gnome-shell Wayland, like this :

#!/bin/bash

function notify-send() {
    
    #Detect the name of the display in use
    local sdisplay=$(echo $XDG_SESSION_TYPE)
    if [ "$sdisplay" == "wayland" ]; then
    local display=":$(echo $WAYLAND_DISPLAY)"
    else
    local display=":$(ls /tmp/.X11-unix/* | sed 's#/tmp/.X11-unix/X##' | head -n 1)"
    fi
    
    #Detect the user using such display
    local user=$(who | grep '('$display')' | awk '{print $1}' | head -n 1)

    #Detect the id of the user
    local uid=$(id -u $user)

    sudo -u $user DISPLAY=$display DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$uid/bus notify-send "$@"
}

notify-send "hi"

but it's not running.

so is there a way to make it work under wayland?

(gnome-shell 3.38.5 - LMDE5(debian 11 bullseye)

markoly
  • 33
  • 4
  • which notification daemon do you have running in Wayland? – stark Oct 03 '22 at 11:21
  • @stark i'm using notify-send (libnotify-bin) – markoly Oct 03 '22 at 12:33
  • 1
    notify-send is a client program that talks to the notification daemon run by the display manager. – stark Oct 03 '22 at 12:38
  • @markoly I use several event notifications in various shell scripts; on Lubuntu, the notification always looked different when sudo-executed from script. I adapted your function above into my logging/messaging system, and now all notify-send events look uniform. I didn't realize how annoying it was until you fixed it. :-) Thank you so much! – nmax Nov 27 '22 at 16:25

0 Answers0