I can run a script at boot by adding the following line to my crontab:

@reboot perl /path/script

That works fine. But the problem arises when I try to run a gui application such as gmail notify. It simply doesn't run.

How do I run a gui application on startup?

  • You mentioned crontab, which confused me now. Run GUI app on startup or everyday ?
    – daisy
    Jul 30, 2012 at 10:04
  • on startup. asfadsfsdf
    – john-jones
    Jul 30, 2012 at 10:06
  • Typically X11 isn't even up yet when cron runs its @reboot action, and even if it is, there are plenty of reasons why you should avoid running X programs from a daemon which has no straightforward way to figure out how to connect to your desktop GUI session even if you have logged in immediately when the system made it possible.
    – tripleee
    Dec 28, 2021 at 18:04

2 Answers 2


Cron is not the program you're after. To run GUI programs there are different approaches. Which one to choose depends on your desktop environment.

The traditional way is to hook it into your .xinitrc file before starting the window manager. A simple example .xinitrc looks as follows:


# Play a login sound
ogg123 -q "${HOME}/Music/login.ogg" &

# Start a terminal emulator
urxvt -T Terminal &

# Start the window manager
exec awesome

Depending on the desktop environment, you can also use ~/.config/autostart/ and create a program.desktop file. Check that directory, if it already contains entries. That's the easiest way, I guess.

autostart […] defines a method for automatically starting applications during the startup of a desktop environment […]

Source: freedesktop autostart specification

  • i dont have a .xinitrc file in my home directory. does it work just like crontab? Also, i have a .config directory under my home directory, but no 'autostart' directory under that. So i cant see any entries there.
    – john-jones
    Jul 30, 2012 at 9:43
  • I added an example ~/.xinitrc configuration. Since you did not specify any details about your system, that is all help I can provide. It is the most generic way and does not depend on the configuration of any particular desktop enviroment or login manager.
    – Marco
    Jul 30, 2012 at 10:06
  • ok so .xinitrc can be just a normal bash file. But it doesn't work. I put 'gmail-notify &' into it, which if i type into the terminal runs the gmail utility. But even though this command is in the .xinitrc, the gmail-notify does not run on startup.
    – john-jones
    Jul 30, 2012 at 10:20
  • 1
    xdg autostart freedesktop specification
    – Marco
    Jul 30, 2012 at 10:33
  • 1
    Ok so the latter part of this answer is the solution, the wording could just be improved a bit. One makes a .desktop file of the given gui application by right clicking it in the menu and placing an entry of it on the desktop. Then one moves that new .desktop file to ~/.config/autostart. Now that given gui app starts automatically at bootup.
    – john-jones
    Jul 30, 2012 at 11:13

I just had a horrible time doing this in Lubuntu, so I thought I would share how I finally got it. Create a .desktop file in /etc/xdg/autostart. You can get the format from freedesktop Desktop Application Autostart Specification and/or just look at other desktop configuration files in that folder. My big problem was that I was trying to put it in the folders listed by the command

echo $XDG_CONFIG_DIRS/autostart

but that gives folders that don't work, as well as the one above. Perhaps, on other systems, you could get a hint about where to put it from

sudo find / -name *.desktop

Another little hint - if you write a .desktop file, you can check it by putting it in your desktop folder. It should show up as an icon, and when opening it, it should run your program.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .