pynotifier icon indicating copy to clipboard operation
pynotifier copied to clipboard

Notifications not showing up on cron

Open yomajo opened this issue 1 year ago • 0 comments

Hey.

Currently I use notifier.sh:

#!/usr/bin/env bash
set -e
# enable notify-send from cron
export XDG_RUNTIME_DIR=/run/user/$(id -u)

PROJECT_DIR="${HOME}/my_project/"
cd "${PROJECT_DIR}"

.venv/bin/python main.py

if tail -2 some.log | grep -q "INTERESTING"; then
	notify-send "Pay attention!"
fi

executing this from cron yields notifications, but when using main.py as:

from pynotifier import NotificationClient, Notification
from pynotifier.backends import platform

c = NotificationClient()
c.register_backend(platform.Backend())
n = Notification(title='test!', message='pay attention')
c.notify_all(notification=n)

and cron:

* * * * * /home/myuser/myproject/.venv/bin/python /home/myuser/myproject/main.py

No notification is shown.

OS: "Ubuntu 22.04.3 LTS" Python 3.10, pipenv

edit: script run as pipenv run python main.py successfully shows notification.

yomajo avatar Dec 02 '23 14:12 yomajo