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.)

  • 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
  • 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

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'
  • 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
  • Adding export DISPLAY=:0 to my cron file actually helped with Error: GDK_BACKEND does not match available displays, thanks! – aexl Aug 24 '18 at 20:17

Not the answer you're looking for? Browse other questions tagged or ask your own question.