Ubuntu Tutorial: How to launch an GUI from cron in Ubuntu

Posted in | »

On Sunday, I spent a good half-hour with Google learning how to launch a GUI application in Ubuntu using cron. I wanted to write a brief post here explaining the process so as to help another weary Googler more quickly on their way.

My situation is this: I use a nifty little flashcard-like study program called Mnemosyne. I use it to study foreign languages and for school. Ideally I should run it daily -- but I often forget, which slows my learning. So I decided to create a cron job which would run the program every day at 7 AM.

Using the normal crontab syntax I made this entry:

0 7 * * * mnemosyne
This, I thought, would run mnemosyne once a day at 7 AM. Unfortunately I was wrong. After much searching around I found the solution on the Ubuntu forums (always a great resource). My problem was that because cron doesn't run in the X session (The program that controls all GUIs in Linux), when you try to run a GUI program, cron doesn't know where to start it. To tell cron where to start the GUI, I changed my crontab entry as follows:
0 7 * * * export DISPLAY=:0 && /usr/bin/mnemosyne

And finally success!

The post on the Ubuntu Forums I found explains all this and more and gives a number of examples.

Also, for those wanting a more general tutorial on crontab syntax, see the crontab article on wikipedia.

Submitted by Kyle Mathews on Wed, 05/02/2007 - 04:07
Erlingur (not verified) Says:
Fri, 10/05/2007 - 01:12

Hi, I'm one of those Googlers you talked about.

Thank you so much for your post! You just saved me one heck of a headache. I had a similar problem to yours. I wanted to have VLC play a certain wakeup playlist for me. And, since I always have my computer on, what better way than cron.

At least you've helped one fellow Googler out! :)