4

I've added the (f)cronjob

*/1 * * * * DISPLAY=:0 notify-send testing

to display a notification every minute, but it doesn't work; why not? (Using i3.)

Toothrot
  • 3,435
  • Have you checked your environment? The $DISPLAY could be :0.0. – Ken Sharp Feb 28 '17 at 12:22
  • @KenSharp, I have. Also, the same command works if I enter it from another tty. – Toothrot Feb 28 '17 at 12:24
  • As what user does this cronjob run? I do believe that root is by default not allowed to use an x-session from a cronjob – Pelle Feb 28 '17 at 12:38
  • @Pelle, running as same user that is logged in to x. – Toothrot Feb 28 '17 at 12:39
  • Very likely an authorization issue. man xauth, and find out how your desktop system/display manager generates MIT cookies (Gnome does some icky things IIRC). ps axu | grep X looking at -auth in the commandline if present may be helpful. – dirkt Feb 28 '17 at 13:08
  • I agree with dirkt, the cronjob works for me but I vaguely recall doing something with xauth for another script a long time ago – Pelle Feb 28 '17 at 13:18
  • I would recommend putting that in a small script and telling cron to run the script. Not sure why but that has worked for me in the past. – Ken Sharp Feb 28 '17 at 14:29
  • 1
    I should add that I solved this simply by putting DBUS_SESSION_BUS_ADDRESS=<...> at the top of my cron file. Works after reboot too on my system. – Toothrot Feb 28 '17 at 15:43
  • @Toothrot You can add that as answer. – Ken Sharp Mar 05 '17 at 13:54

1 Answers1

3

It doesn't work as a cronjob because crontab runs in background. You need to set the variable for it, like this:

*/1 * * * * <user> export DISPLAY=:0 && notify-send 'testing'
13dimitar
  • 1,529
  • 1
    This doesn't work either. – Toothrot Feb 28 '17 at 12:30
  • Crontab is running in the background, and it doesn't show anything because there's no graphic output specified. You can specify it by adding export DISPLAY=:0 in your crontab entry (of course assuming DISPLAY:=0 is the correct display, but you pointed that out in a comment to your question). – 13dimitar Feb 28 '17 at 12:34
  • You have added export which it seems makes the var available to sub-processes, but that doesn't seem to be the crucial thing here. – Toothrot Feb 28 '17 at 12:36
  • 1
    I think you also need to specify an user which is able to log in to x. – 13dimitar Feb 28 '17 at 12:43
  • 1
    Adding export DISPLAY=:0 to my cron file actually helped with Error: GDK_BACKEND does not match available displays, thanks! – ᴍᴇʜᴏᴠ Aug 24 '18 at 20:17