用于发送桌面通知的脚本和模块

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 IDnotify-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,但有几个改进,包括透明背景的可能性和存储通知的通知中心。在

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
我可以用C++代码使用java代码吗?   java使用JSR303在派生类中提供更具体的约束   java在这个查找唯一路径数算法中我做错了什么?   java如何为2个不同的服务提供商使用2个不同的SSL证书?   java在Gridview上绘制文本   java使用连接for循环构建字符串名   java StringBuilder拆分无法处理某些文件   java事件关注EditText   Java Web Start“找不到URL的缓存资源”   java程序从命令行运行的速度比在Eclipse中慢   java为什么HttpServletRequest会截断#字符上的url输入?   java自定义折叠工具栏平滑标题大小调整   使用Mockito对安卓 java中调用另一个静态函数的函数进行单元测试   http在java客户机中使用cachecontrol头   java如何使用。是否使用Delimiter从输入文件中排除标点符号和数字?   使用上下文作为参数/参数的java   java更有效地从Jar中提取文件   java为多个JButton提供相同的actionListener