Page 1 of 4 123 ... LastLast
Results 1 to 10 of 33

Thread: crontab: How to run GUI programs with cron

  1. #1
    Join Date
    Apr 2005
    Location
    Sintra, Portugal
    Beans
    835

    crontab: How to run GUI programs with cron

    This is an updated Thread from 5.10. It works on 6.06.


    First of all, please refer to this howto to learn more about crontab.


    My motivation to find this out was because there are several radio shows I really like and I was always missing them. As such, I needed something to make amarok play the chosen radio station at specific times. Probably this could be achieved through a more elegant solution, but what is explained here works great. Also, I knew that by learning how to do this, I could use it for many other things.

    To accomplish this, you have to edit your crontab:

    Code:
    crontab -e
    you can also use a nicer GUI tool to edit crontab, like gnome-schedule or KCron (both available on the repositories).

    If you use a GUI tool, please adapt the instructions accordingly. I will explain this using as basis the default crontab editor.

    To run a GUI command on cron, you'll have to tell cron what display the program should use. For that you use:

    Code:
    export DISPLAY=:0
    The ':0' is the default. If you like the program to run on other display, please change the number accordingly (e.g. :1, :2, etc).

    So, you add to what is explained here:

    Code:
    01 04 * * * /usr/bin/somedirectory/somecommand
    the export variable, like this:

    Code:
    01 04 * * * export DISPLAY=:0 && /usr/bin/somedirectory/somecommand
    You can omit the full path to the application bin. For amarok, you just need to use the 'amarok' command. Works fine both ways.

    So, in my case, as I want amarok to play Antena2 (Portuguese classical radio station) at a specific time, I use:

    Code:
    30 16 * * 7     export DISPLAY=:0 && amarok mms://rdp.oninet.pt/antena2
    This will make amarok start the Antena2 url every Sunday, at 16:30. But I want also to shut up amarok after the show is finished. So, I use:

    Code:
    0 17 * * 7     export DISPLAY=:0 && amarok -s
    This will shut up amarok at 17:00 every Sunday.

    (Just a side note - to make amarok play mms urls, you have to set it to use xine engine)

    You can use this export trick to the limits of your imagination with every kind of application you want.

    Another example that occurs to me is when you neet to use an application for a certain period of time, from 3AM to 9AM, for exemple.

    Code:
    0 3 * * * export DISPLAY=:0 && your_favorite_application
    that will start your_favorite_application (change this to the command that runs the application you desire) everyday at 3AM. To shut it down, I use:

    Code:
    0 9 * * * killall your_favorite_application
    This will shut it down at 9AM.

    Hope this helps some of you.

    If you have more ideas how to use this trick (or how to improve this HowTo), please share with us in this thread.
    Last edited by henriquemaia; January 16th, 2008 at 01:25 PM.

  2. #2
    Join Date
    Oct 2005
    Location
    Europe
    Beans
    96
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: crontab: How to run GUI programs with cron

    Thanks a lot !
    It started to drive me crazy

  3. #3
    Join Date
    Jun 2005
    Location
    Belgium
    Beans
    58
    Distro
    Ubuntu 7.04 Feisty Fawn

    Re: crontab: How to run GUI programs with cron

    That is a very neat trick, thank you! (I was looking earlier for something like that)

  4. #4
    Join Date
    Apr 2005
    Location
    Sintra, Portugal
    Beans
    835

    Re: crontab: How to run GUI programs with cron

    To both previous posters, I just like to say that I'm very glad that this HowTo helped you. When I found this, I was going mad trying to accomplish this without success. It's really nice to be able to share knowledge.

  5. #5
    Join Date
    Jan 2006
    Location
    New York
    Beans
    769
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: crontab: How to run GUI programs with cron

    Bravo! Thank you for the info. This helped me a lot!
    How to install and run Photoshop 7 or earlier in wine
    Switched to Linux completely 1 January 2007 Ahh, a solid year of freedom
    My Website

  6. #6

    Re: crontab: How to run GUI programs with cron

    Thank you SO much. This is one of the most useful threads I've ever found on this forum. I had been trying to find a fix to this problem for weeks, and none of them worked -- except this one.

  7. #7
    Join Date
    Mar 2005
    Location
    Malaysia
    Beans
    300
    Distro
    Ubuntu 6.06 Dapper

    Re: crontab: How to run GUI programs with cron

    Hi henriquemaia,

    Firstly, thanks for this useful post the DISPLAY=:0 did the trick for me. Previously I was wondering why my stuff didn't run

    Actually, I have a question though.

    When you say "DISPLAY" here, are we talking about desktop workspaces? Cause I have a teeny little problem.

    I'm trying to run the command:
    Code:
    rhythmbox-client --play-pause"
    And it does run. The only problem is, that it launches a new instance of rhythmbox(therefore I have 2 music players). If I directly type the command "rhythmbox-client --play-pause" into the terminal, it just pauses/plays the current instance of rhythmbox, and doesn't create a new instance. Is this caused by the DISPLAY?

    Hope you can enlighten me on this

    Thanks,
    Kinson.

  8. #8
    Join Date
    Nov 2006
    Beans
    35

    Re: crontab: How to run GUI programs with cron

    thanks a million - that did the trick. I was just about to give up altogether...

  9. #9
    Join Date
    Jul 2007
    Beans
    1

    Re: crontab: How to run GUI programs with cron

    I was just about to give up when I find this... thaanks

  10. #10
    Join Date
    Jan 2007
    Beans
    36

    Re: crontab: How to run GUI programs with cron

    Thanks.

Page 1 of 4 123 ... LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •