Running notify-send as root under Wayland

950 Views Asked by At

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)

0

There are 0 best solutions below