Dem*_*ler 6 linux notifications shell-script cinnamon
在我的脚本中,我向用户发送通知并提示他输入一些数据。之后我想清除之前发送的通知。通知应保留在托盘中,直到用户输入数据。
目前我正在使用notify-send,但只能通过超时才能清除。
我想要的是这样的:
send-notification --title="Hey, enter some data pls" --id=999
prompt-to-enter-data
delete-notification --id=999
Run Code Online (Sandbox Code Playgroud)
我正在使用 linux Mint 20。带有 cinnamon DE (v4.6.6)。
notify-osd未安装。
这是可能的,但不是与notify-send. 您需要使用不太专业的工具(例如gdbus. 它将允许您从 shell 调用各种方法。
另一种选择是dbus-send,但它(至少目前)不支持variant该方法所需的类型org.freedesktop.Notifications.Notify。我们将坚持gdbus。
查看man 1 gdbus。它包括一个发送通知的示例:
Run Code Online (Sandbox Code Playgroud)gdbus call --session \ --dest org.freedesktop.Notifications \ --object-path /org/freedesktop/Notifications \ --method org.freedesktop.Notifications.Notify \ my_app_name \ 42 \ gtk-dialog-info \ "The Summary" \ "Here's the body of the notification" \ [] \ {} \ 5000
这应该打印通知 ID(uint32 42,)所在的位置。42事实上,该示例42明确指定,这意味着如果已经存在具有该确切 ID 的通知,那么它将被替换。要创建全新的通知,请指定0。硬编码 ID(如999您的问题中所示)是可能的,但如果 ID 已被某些不相关但可能重要的通知占用怎么办?因此指定0、捕获输出、隔离新 ID 并将其与 一起使用org.freedesktop.Notifications.CloseNotification。
有用的链接:
示例脚本:
#!/bin/sh
tty="$(tty)"
id="$(gdbus call --session \
--dest org.freedesktop.Notifications \
--object-path /org/freedesktop/Notifications \
--method org.freedesktop.Notifications.Notify \
my_script \
0 \
utilities-terminal \
"Response required" \
"Script awaiting input ($tty)." \
[] \
{} \
0
)"
id="${id##* }"
id="${id%,)}"
printf 'Type here and hit Enter: '
read foo
>/dev/null gdbus call --session \
--dest org.freedesktop.Notifications \
--object-path /org/freedesktop/Notifications \
--method org.freedesktop.Notifications.CloseNotification \
"$id"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1848 次 |
| 最近记录: |