Skip to main content

Script and module for sending desktop notifications

Project description

A python script for sending desktop notifications from the shell.

About

Libnotify is part of many scripts in the Linux world. It utilizes many of the specified features of the Desktop Notifications Specification and makes them accessible to shell-scripts. It does not however allow to replace an existing notification with the replaces-id. This is a known bug since 2008 and has a patch since 2012. The patch is still not upstream though (2018).

This python script utilizes the notify2 package and exposes the functionality to the shell.

Differences between notify-send.py and notify-send

  • In notify-send.py -h shows help instead of being the parameter for hints. For hints use --hint.

  • In notify-send.py -r ID and notify-send.py --replaces-id ID exists. In order to replace a notification call notify-send.py with the ID that was returned by the notification to be replaced.

  • notify-send.py returns the ID of the newly created notification.

  • notify-send.py --replaces-process NAME exists. Every notification that gets created with the same NAME will replace every notification before it with the same NAME. If called with this parameter notify-send.py might block, best to be called with a trailing &.

  • notify-send.py -h has action-support (buttons). Try notify-send.py "Yes or no?" --action ok:OK cancel:Cancel

Installation

Requires python 3.

From PyPI:

pip install notify-send.py

From repo:

git clone https://github.com/phuhl/notify-send.py
cd notify-send.py
pip install .

Usage

$ 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.

notify-send[.py] as root user

In order to display notifications, even if libnotify or notify-send.py is used from the root user this script is helpful. You need to customize it with your username and userid (which probably is 1000 but can be found out by running cat /etc/passwd | grep <username>).

notify-send-from-root.sh:

#!/bin/bash
USERNAME=<your username here>
USERID=1000

export XAUTHORITY=/home/$USERNAME/.Xauthority
export DISPLAY=:0
export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$USERID/bus

if [ "$(/usr/bin/id -u)" != "$USERID" ] ; then
    sudo -u $USERNAME XAUTHORITY=/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

Examples (Volume and Brightness pop-ups)

See also

Also take a look at my notification-daemon inspired by Dunst, but with several improvements, including the possibility of a transparent background and a notification center that stores notifications.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

notify-send.py-1.2.1.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

notify_send.py-1.2.1-py2.py3-none-any.whl (6.4 kB view details)

Uploaded Python 2Python 3

File details

Details for the file notify-send.py-1.2.1.tar.gz.

File metadata

  • Download URL: notify-send.py-1.2.1.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.23.0

File hashes

Hashes for notify-send.py-1.2.1.tar.gz
Algorithm Hash digest
SHA256 ae4573ca4a4071cd38dfc97b13a18a48124cdf9f23cd6b347bbd23284de31260
MD5 f255a73377062acbdcc30d03bcb90c92
BLAKE2b-256 c9b0d87c07159cab5a244d5991ca6c1e267f04418c1008e3e080ac4fcc99a923

See more details on using hashes here.

File details

Details for the file notify_send.py-1.2.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for notify_send.py-1.2.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 f5768c8ba846a42f39da669b3f81f7d61a396693e53819da31744446231778b6
MD5 26f65cd106945b4e20fb1f44bef92897
BLAKE2b-256 a8c111fdc417313f11a43d79406877793198f831eb2d677f23fb3eaba1ae8ea1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page