gpt4 book ai didi

php - Ubuntu - PHP |通过 PHP 调用时,notify-send 看起来不同

转载 作者:行者123 更新时间:2023-12-04 18:31:44 26 4
gpt4 key购买 nike

我目前正在构建一个 php 命令行应用程序,我使用 notify-send在我的 Ubuntu 17.10 中发送通知现在带有 gnome。
通知看起来很好,当我在终端中手动运行 cli 应用程序时它们应该如此。 (在顶部,在通知中心)
enter image description here
但是当同一个应用程序通过 cron 作业运行时,通知看起来完全不同,并且显示在不同的位置! (右上)
enter image description here
我正在使用 exec('notify-send tas) 在我的应用程序中调用通知发送
我对外观略有不同的通知的问题是我无法点击超链接!而另一个支持点击超链接,然后打开网页。
这里出了什么问题?

最佳答案

经过大量的研究、试验和错误。我得到了下面的解决方案!

PHP 代码将调用一个 shell 脚本,该脚本实际上会发送 libnotify信息。

bash 脚本:


#!/bin/bash
#
# This script shows how to send a libnotify message
# to a specific user.
#
# It looks for a process that was started by the user and is connected to dbus.

# process to determine DBUS_SESSION_BUS_ADDRESS
USER_DBUS_PROCESS_NAME="gconfd-2"

NOTIFY_SEND_BIN="/usr/bin/notify-send"

TITLE=$1
MESSAGE=$2

# get pid of user dbus process
DBUS_PID=`ps ax | grep gconfd-2 | grep -v grep | awk '{ print $1 }'`

# get DBUS_SESSION_BUS_ADDRESS variable
DBUS_SESSION=`grep -z DBUS_SESSION_BUS_ADDRESS /proc/$DBUS_PID/environ | sed -e s/DBUS_SESSION_BUS_ADDRESS=//`
# echo $DBUS_SESSION;

# send notify
DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION $NOTIFY_SEND_BIN "$TITLE" "$MESSAGE"

PHP代码:

$command = sprintf('/path/to/bash_script.sh "%s" "%s" 2> /dev/null', $title, $message);
system($command);

PS:这用于命令行应用程序,每当在 stackoverflow.com 上发布新问题时,该应用程序都会发送系统通知! (与您的标签匹配的问题)

你可以在这里查看: https://kerneldev.com/2017/12/27/so-notify-a-stack-overflow-question-notifier/

关于php - Ubuntu - PHP |通过 PHP 调用时,notify-send 看起来不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47832724/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com