Broadcast version of notify-send to allow root processes to send a notification to all users with an active DBUS session
Project description
notify-broadcast
This program was developed because I run a number of cron jobs as root that I would like to be able to send notifications to the GUI User
notify-send only functions if run by the same user running the graphical session.
I created notify-broadcast to effectively take the same parameters as notify-send but that
could be executed by the root user.
The application searches for all active DBUS Notification sessions, and sends the notification to all currently attached users.
Installation
When complete, should be:
pip install notify-broadcast
Seek information elsewhere about installing in a virtual environment
The install should pull in all dependencies. At present these are:
- colorlog: https://github.com/borntyping/python-colorlog/
- dasbus: https://github.com/dasbus-project/dasbus
- psutil: https://github.com/giampaolo/psutil
- PyGObject: https://pygobject.gnome.org
Usage
# notify-broadcast --help
usage: notify-broadcast [--help] [-a APP_NAME] [-i ICON] [-t EXPIRE_TIME] [-h TYPE:NAME:VALUE] [-c TYPE] [-u {low,normal,critical}] [-A NAME=VALUE]
[-r REPLACE_ID] [-p] [-e HINT] [-L] [-R] [--log-level {DEBUG,INFO,WARNING,ERROR,CRITICAL}] [--global-log-level {DEBUG,INFO,WARNING,ERROR,CRITICAL}]
summary body
Notify Broadcast Send a Broadcast DBUS notification to all users
positional arguments:
summary Notification summary - used as heading for notification
body Notification detail - primary notification text
options:
--help show this help message and exit
-a APP_NAME, --app-name APP_NAME
Specifies the app name for the notification
-i ICON, --icon ICON Specifies an icon filename or stock icon to display. (default: dialog-information)
-t EXPIRE_TIME, --expire-time EXPIRE_TIME
The duration, in milliseconds, for the notification to appear on screen. Value of 0 means no expiry, while -1 uses the server default
expiry. (default: -1)
-h TYPE:NAME:VALUE, --hint TYPE:NAME:VALUE
Notification hints to pass to server (e.g., int:urgency:2)
-c TYPE, --category TYPE
Specifies the notification category.
-u {low,normal,critical}, --urgency {low,normal,critical}
Specifies the urgency level (low, normal, critical).
-A NAME=VALUE, --action NAME=VALUE
Specifies the actions to display to the user. Implies --wait to wait for user input. May be set multiple times. The NAME of the action
is output to stdout. If NAME is not specified, the numerical index of the option is used (starting with 1).
-r REPLACE_ID, --replace-id REPLACE_ID
The ID of the notification to replace.
-p, --print-id Print the notification ID.
-e HINT, --transient HINT
Show a transient notification. Transient notifications by-pass the server's persistence capability, if any. And so it won't be preserved
until the user acknowledges it.
-L, --local Send notification to all TTY local sessions
-R, --remote Send notification to all TTY remote(ssh) sessions
--log-level {DEBUG,INFO,WARNING,ERROR,CRITICAL}
Set the logging level for the core application.
--global-log-level {DEBUG,INFO,WARNING,ERROR,CRITICAL}
Set the global logging level (includes third-party libraries).
NOTE: For more support on these parameters, see notify-send man pages
Examples
Some examples of how to use notify-broadcast are listed below. These are by no means exhaustive:
notify-broadcast -a Daily-backup -t 0 -i dialog-information.png "Backup completed without error" ""
Display a notification that the backup has completed without error:
- Display an information icon
- A timeout of 0 signifies that the notification will display until the user clears it
- Message contains a summary, but no body
notify-broadcast -a Remote-rsync -t 6000 -i dialog-warning.png "Remote host not currently on the network" ""
Display a notification that the remote host is not available:
- Display a warning icon
- A timeout of 6000 signifies that the notification will display for six seconds before clearing
- Message contains a summary, but no body
notify-broadcast -a Daily-backup -t 0 -i dialog-error.png "Error running backup, please consult logs" ""
Display a notification that the backup has completed without error:
- Display an error icon
- A timeout of 0 signifies that the notification will display until the user clears it
- Message contains a summary, but no body
notify-broadcast -a "Disk Monitor" -h string:desktop-entry:org.kde.kinfocenter-i drive-harddisk "Disk" "SMART warning"
Display a notification that a disk has encountered a SMART error:
- Display an disk icon
- No timeout signifies that the notification will display for the system default duration
Comments
I am aware of a number of potential shortcomings that may impact broader distribution, as well as some points about why things were coded this way, details listed below
Finding DBUS Path via environment variables instead of /run/user/{uid}/bus
The code searches for the DBUS_SESSION_BUS_ADDRESS environment variable in a running program,
while many online examples suggest searching /run/user/{uid}/bus
My system (Gentoo) does not place the DBUS sockets in that location, so searching the environment variables allows this to work regardless of the location of the socket.
Program is hard-coded to KDE
As per the previous point, to search the environment variables, it means finding a running application that has the environment variables set. This means that we need to know the application name to search for.
Hence, the program currently looks for running instances of kwin_wayland or kwin_x11 depending
on the current session type.
This works for me as I use KDE, I don't like Gnome or other environments.
However, I realise this means that this will not work everywhere. Some chat online suggests looking
for dbus-launch, however the environment for this process does not appear to contain the
DBUS_SESSION_BUS_ADDRESS environment variable.
I would like to support alternate desktops, but I do not have the will to test and develop a solution. I am happy to take comments/suggestions on how to detect across multiple platforms.
Some of the Options are Useless for Broadcast application
As a broadcast application, this really makes sense as a 1) send a message; and 2) do not wait for replies scenario
--print-idmakes no sense if sending multiple notifications--replace-idmake no sense if we are just blasting information to everyone--actiondisplay buttons to the user and return values to the program. This is generally useless for this application
Running as non-root
A non-root user will not be able to post notifications to other users in either case. The application currently just prints warnings about being unable to access the environment and does nothing else.
It might be better to abort early if the user does not have permissions, but a system could allow multiple users the requisite permissions, so it is hard to manage this properly.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file notify_broadcast-0.0.4.tar.gz.
File metadata
- Download URL: notify_broadcast-0.0.4.tar.gz
- Upload date:
- Size: 14.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1cfeaa34d0d8030262d9e21d9138aec403b8133dd3632609e77416a25d0d9a64
|
|
| MD5 |
d8631e7426e91c4c2689d2bdd090ea26
|
|
| BLAKE2b-256 |
27e07c473aa99994ce2776061dd01e927192d5d7eb402a68177bcfaec795b302
|
Provenance
The following attestation bundles were made for notify_broadcast-0.0.4.tar.gz:
Publisher:
python-publish.yml on jason-but/notify-broadcast
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
notify_broadcast-0.0.4.tar.gz -
Subject digest:
1cfeaa34d0d8030262d9e21d9138aec403b8133dd3632609e77416a25d0d9a64 - Sigstore transparency entry: 1993879060
- Sigstore integration time:
-
Permalink:
jason-but/notify-broadcast@82b0c0d9b3bb1d3a42d8c5296483a4898eac7ae9 -
Branch / Tag:
refs/tags/0.0.4 - Owner: https://github.com/jason-but
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@82b0c0d9b3bb1d3a42d8c5296483a4898eac7ae9 -
Trigger Event:
release
-
Statement type:
File details
Details for the file notify_broadcast-0.0.4-py3-none-any.whl.
File metadata
- Download URL: notify_broadcast-0.0.4-py3-none-any.whl
- Upload date:
- Size: 15.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
147f9003aa46059e8526b4412959cda77e4f58fc7840bb9dc13fb8267573afbb
|
|
| MD5 |
d65c01302a506362cd7de77082467995
|
|
| BLAKE2b-256 |
04bab87d6adae4d66b46670449947db5335d04b46610148e4e96965e80d0e172
|
Provenance
The following attestation bundles were made for notify_broadcast-0.0.4-py3-none-any.whl:
Publisher:
python-publish.yml on jason-but/notify-broadcast
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
notify_broadcast-0.0.4-py3-none-any.whl -
Subject digest:
147f9003aa46059e8526b4412959cda77e4f58fc7840bb9dc13fb8267573afbb - Sigstore transparency entry: 1993879187
- Sigstore integration time:
-
Permalink:
jason-but/notify-broadcast@82b0c0d9b3bb1d3a42d8c5296483a4898eac7ae9 -
Branch / Tag:
refs/tags/0.0.4 - Owner: https://github.com/jason-but
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@82b0c0d9b3bb1d3a42d8c5296483a4898eac7ae9 -
Trigger Event:
release
-
Statement type: