Desktop environment autostart

Couple a years ago the following specification has been written. It specifies the way to autostart applications on login and after mounting devices. As this is a desktop environment feature, most of the explanations assume using GUI to set the startup applications.

However, it’s perfectly possible to do this from the command line. As per the above specification, to start the application on login, you need to create a .desktop file and put it in a specific location. Usually, this is ~/.config/autostart, but read Autostart Directories from the specification for further rules. Format of the .desktop files is explained in a separate document. Most of the entries are optional, but some are required.

Let’s test this. First, obviously there’s a need to run something. Let’s write a dummy script for our test purposes:

echo I ran after you logged in, around `date +"%F %T"` > /tmp/run-at-logon.out

Save it as ~/ and then:

$ chmod u+x ~/

to make it runnable. Test it:

$ ~/ 
$ cat /tmp/run-at-logon.out
I ran after you logged in, around 2011-03-21 23:11:53

Now, let’s make a sample .desktop file for our test script. Here it is:

[Desktop Entry]
Name=Run at logon

That’s it. Save the file to ~/.config/autostart/run-at-logon.desktop.

Multiple XWindow sessions

To test the above, we need to logout and login. Tiresome – let’s make it easier. As per this thread, you can switch to some console (e.g. Ctrl+Alt+F1), login there and then run the following command:

$ xinit /usr/bin/gnome-session -- :1

This will run another session on the next available pts, which in my case was 3, so to get to it you do Ctrl+Alt+F3, to return to your normal Gnome session you do Ctrl+Alt+F7. Now, while in the new session, open the terminal with Ctrl+Alt+T and check that /tmp/run-at-logon.out was created.

If all went well, just kill xinit on pts 1 and also remove the scripts we created unless you still want to have them running each time you login.