I have following python script, and want to run it with cron so that every minute cron will popup a message.
#!/usr/bin/python
# -*- coding: utf-8 -*-
import gtk.gdk
import pynotify
import random
m=[]
m.append("test1")
m.append("test2")
m.append("test3")
n = pynotify.Notification(random.choice(m))
n.set_hint('x', gtk.gdk.screen_width()/2.)
n.set_hint('y', gtk.gdk.screen_height()/2.)
n.show()
This is my cron script:
* * * * * export DISPLAY=:0.0 && /home/user/scripts/notifications.py >/dev/null 2>&1
Unfortunately nothing happens. Can you help please?
In case anyone else is wondering. I had to export DISPLAY and XAUTHORITY
I'm running this script in cron:
From this thread at Ubuntuforums, you're possibly running into
xauth
problems. X tends to be paranoid about giving display/input access to outside processes, even from the same user.In an X terminal window, type:
xhost local:$USER
and see if your cron job works. If so, add that command to your~/.bashrc
file and the fix should persist.