2

In my Ubuntu 16.04 , 64 bit OS, I tried the following

* * * * * export DISPLAY=:0.0 && notify-send Hey "How are you"

And

* * * * * export DISPLAY=:0.0 && /usr/bin/notify-send Hey "How are you"

But, unfortunately, it is not working.

I found in other threads that the above command works.

How to run it on my machine?

The command notify-send Hey "How are you" works on the terminal.

Also the command * * * * * echo "trying to notify at $(date)" >> /home/user/Desktop/test.txt works fine from crontab file

The output of $ echo $DISPLAY is :0

also

$ who -u
cosmicraga   tty7         2016-11-07 06:45 06:12        2524 (:0)
cosmicraga   pts/1        2016-11-07 12:54   .          6333 (:0)
cosmicraga   pts/17       2016-11-07 12:50 00:02        6333 (:0)
Zanna
  • 72,312
cosmicraga
  • 649
  • 3
  • 8
  • 21

1 Answers1

3

Create notify.sh file in the home directory.

#!/usr/bin/env bash

username=$(/usr/bin/whoami)
pid=$(pgrep -u $username nautilus)
dbus=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$pid/environ | sed 's/DBUS_SESSION_BUS_ADDRESS=//' )
export DBUS_SESSION_BUS_ADDRESS=$dbus

/usr/bin/notify-send "How are you"

In the crontab :

* * * * *  DISPLAY=0:0 /bin/sh /home/YOURUSERNAME/notify.sh
Walk
  • 171
  • 6