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
  • 70,465

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
  • I'm sorry but this solution does not works. I'm still not getting the notification – Gardezi Jul 10 '17 at 07:06
  • 1
    it worked like a charm. @Gardezi, create notify.sh file in your home directory with the first content supplied by @Sonu, then open crontab with crontab -e command in command line. than type the second content supplied by Sonu to the end of the file, use these shortcuts to save and exit: CTRL + O, ENTER, CTRL + X... That's it. but, please don't forgot to change the "netcoreps1" text in the second content supplied by @Sonu, with your current username.. for example: * * * * * DISPLAY=0:0 /bin/sh /home/YOURUSERNAME/notify.sh.. it should work at start of every minute. –  Nov 08 '17 at 00:28
  • 1
    @Interesting Knox , Thats correct. I have improved my answer as per ur comment. Thanks. :) – Walk Dec 05 '17 at 06:10
  • finally this worked for me :) – Sudip Bhandari May 21 '19 at 18:36