Skip to content

Instantly share code, notes, and snippets.

@shvchk
Last active March 15, 2023 06:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save shvchk/ba2f0da49bf2f571d6bf606d96f289d7 to your computer and use it in GitHub Desktop.
Save shvchk/ba2f0da49bf2f571d6bf606d96f289d7 to your computer and use it in GitHub Desktop.
Send notification to a user via notify-send
#! /usr/bin/env bash
# Usage: notify-user.sh username notify-send-args
uid=$(id -u $1)
displays=($(who | grep -E "$1 .+\(:[0-9](\.[0-9])*\)" | awk '{print $NF}' | sort -u))
for display in $displays; do
sudo -u $1 DISPLAY=${display:1:-1} \
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$uid/bus \
notify-send "${@:2}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment