K Module -> KDE Autostart Guide

Ready, Set, Go!

The Ultimate Guide to KDE Session Management and Autostarting

Version 1.0 - 20080422

  1. Getting Started
  2. KDE Session Management [Basic]
    1. Login Options
    2. Manual Autostart
  3. Details, Details [Advanced, Optional]
    1. Sneak peek into starting KDE
    2. Putting it all together
    3. Tips
  4. And Away We Go!
  5. Endnotes
  6. References

I. Getting Started

One of the most frequently asked questions (FAQ) about KDE is how to start applications when the user logs into a KDE session. The answer is not always as straightforward as one would hope, and sometimes quite scattered across several sources. This guide attempts to complete guide to how to manage sessions and autostart applications in KDE, as well as to provide a central reference for links related to the topic.

The first part of this guide gives easy instructions on how to use KDE's powerful session management and on how to start apps after logging into KDE. The third part gives a bit more technical (but not so heavy) details on the startup process and tips on how to take advantage of that.

This guide only applies to KDE 3.5.9. I'll be updating with KDE 4 information it once I've played enough with the new tools.

II. KDE Session Management

KDE has a very powerful session management system, handled by ksmserver. Not only is it able to save and restore applications from previous sessions, it can also save the *state* of KDE applications. This means that ksmserver remembers what applications are open, where the windows are located, as well as what those applications were doing. For example, if you left KWrite open with some text file, KDE will remember that and will restore KWrite with the same text file the next time you log in. If you have unsaved work, you will be prompted whether you want to save it.

Unfortunately, the state of non-KDE apps are not saved in a session and only their window locations are included. The user has to make sure that he or she saves whatever is opened in those apps. KDE will not warn them before logging out if an opened file needs to be saved first. Also, KDE will not be able to restore whatever files those apps have opened when you logged out. [1]

You can control KDE's Session Management options in KControl -> KDE Components -> Session Manager. (Kubuntu users will see it in System Settings -> Advanced tab -> Session Manager). For the purpose of running apps on startup, we just need to focus on the On Login and Advanced options, indicated by the highlighted areas in the images below.

KControl - Session Manager Module

KControl - Session Manager Module

System Settings - Advanced tab

System Settings - Advanced tab

A. Login options

There are three ways ksmserver handles sessions when logging in:

1. Restore previous session

This is the default behavior. KDE will automatically save the session when you logout and will restore it the next time you log back in. KDE will save remember the applications and windows that were left open, their locations, as well as their state (for KDE-aware apps). This is also the easiest way to start apps when you login. Just leave those apps running before you logout. However, this works best with KDE applications only. Remember that non-KDE apps only get started when logging in, but their states are not saved nor restored. Non-GUI programs such as scripts or processes also do not get saved. It can also be a bit cumbersome at times, when you fail to close some apps before logging out.

2. Restore manually saved session

Midway between automatically saving sessions at logout and not saving sessions at all is the option to control when a session is saved and what will be saved in the session. Once this option is chosen (and the Apply button is clicked), a new entry in the K Menu appears: Save Session. Selecting this menu entry will let you save a "snapshot" of the session which will be restored the next time you log in. You can save the session at any point in time and as many times as you want, but only the most recent snapshot is remembered. When this option is used, the session is no longer automatically saved when logging out.

K Menu - Save Session

K Menu - Save Session

3. Start with an empty session

At the other extreme of the pendulum, this option disables KDE from restoring any saved session. This will start KDE with a blank slate everytime, with only system-define apps autostarted on logging in. This is usually used in tandem with manually defining autostarted apps, which will be discussed in a while. When using this option for the first time after a fresh install of a KDE Linux or BSD distribution, keep in mind that some distributions might be using saved sessions to restore some applications that you would normally see when you login, such as KMix or Katapult in Kubuntu. Take note of what apps are restored on your distribution and which ones you'd like to keep autostarting.

4. Excluding applications

Before we jump to the next method, let's consider one more scenario. Let's say you've chosen to restore automatically or manually saved session and there are some apps that you always forget to close before you logout or save the session. What if you didn't want them to be saved and restored? KDE allows you to list programs that you want to be excluded from sessions. At the bottom part of the Session Manager dialog, you can enter a list of programs (using their executable filenames) that you don't want to be saved and restored in sessions, separated by commas with no spaces in between.

The Session Manager control module has some other features that you can read about by clicking on the "What's This" button (the one with the question mark at the upper right corner of the window) and clicking on an area of interest. You can also read the documentation by clicking on the Help button or reading it online. [2]

B. Manual Autostart

You can also specify one by one what apps you want to get autostarted when you login. While this might be a bit troublesome to setup at first, specially if you want to autostart many items, it gives you more control over those items and usually need to be done only once. This way of autostarting apps is commonly used when the Session Manager is set to start with an empty session, but it can also be used together with the other two options.

Manually autostarting applications simply involves putting items into the $KDEHOME/Autostart folder. $KDEHOME stands for the current user's place for storing KDE settings and data, usually ~/.kde (/home/username/.kde) in KDE 3.5 systems. You can easily go to this location by typing ~/.kde/Autostart in Konqueror's location bar, or by clicking Go -> Autostart from Konqueror's menu bar (Kubuntu users will have to type the location themselves).

1. Drag and Drop

There are two ways to put items into the Au