以root身份发送通知(如使用notify Send)到现在运行的用户上 @ shenmo | 2022-08-05T16:35:01+08:00 | 1 分钟阅读 | 更新于 2022-08-05T16:35:01+08:00

百度只能搜到国内的收费的文档

Stack Overflow抄的

如果你要使用notify-send的脚本,把这个东西放到最前面,你就会发现可以发送到当前启动的用户桌面上了

function notify-send() {
    #Detect the name of the display in use
    local display=":$(ls /tmp/.X11-unix/* | sed 's#/tmp/.X11-unix/X##' | head -n 1)"

    #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 "$@"
}

来源: https://stackoverflow.com/questions/28195805/running-notify-send-as-root

© 2019 - 2024 shenmo的世界

Hugo theme Dream.

辽ICP备2021012180号-1

上面有备案号的

avatar
关于我

星火应用商店项目 Leader

社交链接

本博客所有文章使用《知识共享 署名-非商业性使用-相同方式共享 4.0》(CC-BY-NC-SA-4.0)协议

这意味着你可以在署名并标明出处的情况下进行非商业转载(转载的文章也需要遵守CC-BY-NC-SA-4.0协议),但不可以进行商业转载