用于发送桌面通知的脚本和模块
notify-send.p的Python项目详细描述
从shell发送桌面通知的python脚本。在
关于
Libnotify是Linux世界中许多脚本的一部分。它利用了很多 桌面通知规范的指定功能 并使它们可以被shell脚本访问。但是,不是 允许用replaces-id替换现有通知。这个 自2008年以来是知名的bug,自2012年起拥有patch。补丁还是没有 上游(2018年)。在
这个python脚本使用notify2包并公开 shell的功能。在
通知之间的差异-发送.py并通知发送
- Innotify-send.py-h显示帮助而不是的参数 提示。对于提示,请使用--hint。在
- 在notify-send.py-r ID和notify-send.py--replaces-id ID 存在。为了替换通知调用notify-send.py 使用要替换的通知返回的ID。在
- notify-send.py返回新创建的通知的ID。在
- notify-send.py--replaces-process NAME已存在。 使用相同名称创建的每个通知都将替换 所有的通知都有相同的名字。如果用这个打电话 参数notify-send.py可能会阻塞,最好使用 尾随&。在
- notify-send.py-h有操作支持(按钮)。尝试 notify-send.py "Yes or no?"--action ok:OK cancel:Cancel
安装
需要python 3。在
来自PyPI:
pip install notify-send.py
从回购:
^{pr2}$使用
$ notify-send.py -h
usage: notify-send.py [-h] [-u LEVEL] [-t TIME] [-a APP_NAME] [-i ICON[,ICON...]] [-c TYPE[,TYPE...]] [--hint [TYPE:NAME:VALUE [TYPE:NAME:VALUE ...]]] [-r ID] [--replaces-process NAME] [--action [KEY:NAME [KEY:NAME ...]]] SUMMARY [BODY] positional arguments: SUMMARY Summary of the notification. Usage of \n and \t is possible. BODY Body of the notification. Usage of \n and \t is possible. optional arguments: -h, --help show this help message and exit -u LEVEL, --urgency LEVEL Specifies the urgency level (low, normal, critical). -t TIME, --expire-time TIME Specifies the timeout in milliseconds at which to expire the notification. -a APP_NAME, --app-name APP_NAME Specifies the app name for the icon -i ICON[,ICON...], --icon ICON[,ICON...] Specifies an icon filename or stock icon to display. -c TYPE[,TYPE...], --category TYPE[,TYPE...] Specifies the notification category. --hint [TYPE:NAME:VALUE [TYPE:NAME:VALUE ...]] Specifies basic extra data to pass. Valid types are int, double, string, boolean and byte. -r ID, --replaces-id ID Specifies the id of the notification that should be replaced. --replaces-process NAME Specifies the name of a notification. Every notification that gets created with the same NAME will replace every notification before it with the same NAME. --action [KEY:NAME [KEY:NAME ...]] Specifies actions for the notification. The action with the key "default" will be dispatched on click of the notification. Key is the return value, name is the display-name on the button.
通知以root用户身份发送[.py]
为了显示通知,即使libnotify或 notify-send.py来自根用户,此脚本很有帮助。 你需要用你的用户名和用户名(可能是 1000,但可以通过运行cat /etc/passwd | grep <username>)找到。在
notify-send-from-root.sh:
#!/bin/bash USERNAME=<your username here> USERID=1000exportXAUTHORITY=/home/$USERNAME/.Xauthority exportDISPLAY=:0 exportDBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$USERID/bus if["$(/usr/bin/id -u)" !="$USERID"];then sudo -u $USERNAMEXAUTHORITY=/home/$USERNAME/.Xauthority DISPLAY=:0 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$USERID/bus /usr/bin/notify-send.py "$@"else /usr/bin/notify-send.py "$@"fi
示例(音量和亮度弹出窗口)
另请参见
另请看一下我的notification-daemon,灵感来自Dunst,但有几个改进,包括透明背景的可能性和存储通知的通知中心。在
- 项目
标签: