首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >org.freedesktop.Notifications.CloseNotification(uint id)可以通过DBus触发和调用吗?

org.freedesktop.Notifications.CloseNotification(uint id)可以通过DBus触发和调用吗?
EN

Ask Ubuntu用户
提问于 2012-09-19 04:28:27
回答 2查看 2.6K关注 0票数 6

参考文献:

关闭按钮通知-osd?

书签:

org.freedesktop.Notifications.CloseNotification(uint id)可以通过DBus触发和调用吗?

目前,这个脚本

代码语言:javascript
复制
dbus-monitor "interface='org.freedesktop.Notifications'" |             \
grep --line-buffered "member=Notify"                     |             \
sed -u -e  's/.*/killall notify-osd/g'                   |             \
bash

将杀死所有挂起的通知。

最好使用org.freedesktop.Notifications.CloseNotification(uint id)来细化要取消的特定目标OSD通知。是否有一个接口方法可以把它放在(in?)上?当发生特定的通知事件时要触发的DBus?

该方法将需要获取notify作为CloseNotification(uint id)的参数。或者,

代码语言:javascript
复制
  qdbus    org.freedesktop.Notifications                \
          /org/freedesktop/Notifications                \
           org.freedesktop.Notifications.CloseNotification(uint id)

如果可以确定(uint id)参数,则可以从shell中使用。实际的命令语法将使用整数来代替(uint id)

也许首先要问的一个更好的问题是“如何找到通知的DBus地址?”

这两种方法都没有正确识别:

代码语言:javascript
复制
gdbus monitor --session --dest org.freedesktop.Notifications

返回

代码语言:javascript
复制
The name org.freedesktop.Notifications is owned by :1.130
...

代码语言:javascript
复制
dbus-monitor "interface='org.freedesktop.Notifications'"

返回

代码语言:javascript
复制
... string ":1.340" ...

事后看来,前一个问题“通知的(uint id)是如何找到的?”对于另一个问题的先前的回答是否很棘手:

https://askubuntu.com/a/186311/89468

提供详细信息,以便可以使用以下任何一种方法:

代码语言:javascript
复制
gdbus call --session --dest org.freedesktop.DBus                                   \
             --object-path /                                                       \
                   --method org.freedesktop.DBus.GetConnectionUnixProcessID :1.16

返回:

代码语言:javascript
复制
(uint32 8957,)

代码语言:javascript
复制
qdbus --literal --session  org.freedesktop.DBus                                  \
                          /                                                      \
                           org.freedesktop.DBus.GetConnectionUnixProcessID :1.16

返回:

代码语言:javascript
复制
8957

弹出通知-OSD涂鸦将以以下方式被击败:

代码语言:javascript
复制
  qdbus    org.freedesktop.Notifications                             \
          /org/freedesktop/Notifications                             \
           org.freedesktop.Notifications.CloseNotification           \
  $(qdbus --literal --session                                        \
           org.freedesktop.DBus                                      \
          /                                                          \
           org.freedesktop.DBus.GetConnectionUnixProcessID :?.???  )

“诀窍”是找到:?.??? DBus地址。

EN

回答 2

Ask Ubuntu用户

发布于 2012-09-19 19:38:29

CloseNotification方法由规格说明定义为D总线方法.然而,它只声明ID是唯一的,非零的,并且小于MAXINT。它不要求ID是调用进程的PID。在成功调用该方法之前,您需要一种获得该ID的方法。

票数 0
EN

Ask Ubuntu用户

发布于 2013-04-12 17:27:16

我知道我有点晚了,但今天我自己也遇到了这个问题,这可能对其他人有用!

首先,安装一个修补好的libnotify-bin,它支持-p选项来打印通知id:

代码语言:javascript
复制
sudo apt-add-repository ppa:izx/askubuntu
sudo apt-get update
sudo apt-get install libnotify-bin

现在有一个示例脚本,它发送通知而不超时,然后在某个命令完成后关闭通知(在本例中,只睡5秒):

代码语言:javascript
复制
notify-send 'Message...' -i dialog-information \
    -t 0 -h int:transient:1 \
    -p >/tmp/notification_id

sleep 5

qdbus org.freedesktop.Notifications \
     /org/freedesktop/Notifications \
      org.freedesktop.Notifications.CloseNotification \
    $(cat /tmp/notification_id)
票数 0
EN
页面原文内容由Ask Ubuntu提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://askubuntu.com/questions/190406

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档