Enabling zenity notifications using cron

Making zenity notifications available using cron as a user is a bit tricky.

Here is the workaround to add to your scripts to make desktop notifications available.

DBUS=$(pgrep -ou $(whoami) mate)
DBUS="$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$DBUS/environ | sed 's/DBUS_SESSION_BUS_ADDRESS=//')"

# Write a notification function
function Notif {
DBUS_SESSION_BUS_ADDRESS="$DBUS" zenity --notification --text="$1" --display=:0

# Test this notification function
Notif "your message"

Set up a cron job to test your function using crontab -e and let’s see the magic

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.