Score:0

Unable to run notify-send from cronjob

ph flag

In my Kubuntu 22.04, a script run by my crontab uses notify-send. However, it doesn't work: there is no pop-up appearing. If I redirect the output (stderr in particular) of the script to a file, this error is printed:

Error calling StartServiceByName for org.freedesktop.Notifications: Timeout was reached

If instead I run notify-send directly from a cronjob,

0 * * * * env DISPLAY=:0.0 notify-send --expire-time=0 --app-name="Test" 'Test text' 1>/tmp/out1 2>/tmp/out2

out1 and out2 are empty; however, this doesn't work as before. The pop-up does not appear.

Is there a way to make notify-send work as expected?

Score:1
cn flag
raj

I guess for notify-send to work in a cron job you have to copy the environment variable DBUS_SESSION_BUS_ADDRESS from your current desktop session and set it in the cron job. Also, notify-send must run as the same user who is currently logged in to the desktop session.

At least that works for me.

BowPark avatar
ph flag
The user is the same. After also setting `DBUS_SESSION_BUS_ADDRESS` it works. Thank you!
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.