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

9
  • Have you checked your environment? The $DISPLAY could be :0.0. Commented Feb 28, 2017 at 12:22
  • @KenSharp, I have. Also, the same command works if I enter it from another tty. Commented Feb 28, 2017 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 Commented Feb 28, 2017 at 12:38
  • @Pelle, running as same user that is logged in to x. Commented Feb 28, 2017 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. Commented Feb 28, 2017 at 15:43

1 Answer 1

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' 
5
  • 1
    This doesn't work either. Commented Feb 28, 2017 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). Commented Feb 28, 2017 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. Commented Feb 28, 2017 at 12:36
  • 1
    I think you also need to specify an user which is able to log in to x. Commented Feb 28, 2017 at 12:43
  • 1
    Adding export DISPLAY=:0 to my cron file actually helped with Error: GDK_BACKEND does not match available displays, thanks! Commented Aug 24, 2018 at 20:17

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.