Cron – Need with crontab and gui python popup

cronpython

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?

Best Answer

In case anyone else is wondering. I had to export DISPLAY and XAUTHORITY

I'm running this script in cron:

export XAUTHORITY=/home/user/.Xauthority
export DISPLAY=:0
python ~/notifications.py
Related Topic