mil*_*ila 5 bash dbus sender-id ubuntu-20.04
我的目标是过滤来自不同应用程序(主要来自不同浏览器窗口)的通知。
我发现在 dbus-monitor 的帮助下,我可以编写一个小脚本来过滤我感兴趣的通知消息。过滤器脚本运行良好,但我有一个小问题:
我从
dbus-monitor "interface='org.freedesktop.Notifications', destination=':1.40'"
Run Code Online (Sandbox Code Playgroud)
命令。我必须添加“destination=':1.40'”,因为在 Ubuntu 20.04 上我总是收到两次相同的通知。以下输出
dbus-monitor --profile "interface='org.freedesktop.Notifications'"
Run Code Online (Sandbox Code Playgroud)
证明原因:
type timestamp serial sender destination path interface member
# in_reply_to
mc 1612194356.476927 7 :1.227 :1.56 /org/freedesktop/Notifications org.freedesktop.Notifications Notify
mc 1612194356.483161 188 :1.56 :1.40 /org/freedesktop/Notifications org.freedesktop.Notifications Notify
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,发件人 :1.277 首先发送到 :1.56,然后这将是发件人到 :1.40 目的地。(只是notify-send hello发送了测试消息)
我的脚本就是这样工作的,但是每次系统启动时,我都必须检查目标号码并相应地修改我的脚本才能工作。
我有两个问题:
我不知道它是否直接解决了您的问题,但您可以使用以下命令询问有关发件人/目的地的详细信息:
$ dbus-send --print-reply --dest=org.freedesktop.DBus \
/org/freedesktop/DBus \
org.freedesktop.DBus.GetConnectionCredentials \
string:':1.277'
Run Code Online (Sandbox Code Playgroud)
假设发件人/目的地仍然可用,它将打印如下内容:
method return time=1677403493.492844 sender=org.freedesktop.DBus -> destination=:1.156069 serial=3 reply_serial=2
array [
dict entry(
string "ProcessID"
variant uint32 4854
)
dict entry(
string "UnixUserID"
variant uint32 502
)
]
Run Code Online (Sandbox Code Playgroud)
或者,如果您只想要进程 ID:
method return time=1677403493.492844 sender=org.freedesktop.DBus -> destination=:1.156069 serial=3 reply_serial=2
array [
dict entry(
string "ProcessID"
variant uint32 4854
)
dict entry(
string "UnixUserID"
variant uint32 502
)
]
Run Code Online (Sandbox Code Playgroud)
..这给出了:
method return time=1677407392.028717 sender=org.freedesktop.DBus -> destination=:1.156472 serial=3 reply_serial=2
uint32 4854
Run Code Online (Sandbox Code Playgroud)
这些和其他内容记录在此处:https ://dbus.freedesktop.org/doc/dbus-specification.html
| 归档时间: |
|
| 查看次数: |
1761 次 |
| 最近记录: |