How to make program autostart only in GNOME

You can edit the startup object in ~/.config/autostart and add this to the end:

OnlyShowIn=GNOME

It's a poorly named option, but it will cause KDE not to start the application.


I don't have kde installed to verify this but I believe adding the application here: System -> Preferences -> Sessions -> Startup Programs is gnome specific.

If that doesn't work you can always put the program in a wrapper script that checks the value of the environment variable $DESKTOP_SESSION. Something like this:

#!/bin/bash
if [ $DESKTOP_SESSION == "GNOME" ];then
        myApplication
fi

Hope this answers your question!


If you cannot find the entry that starts a program, you might also find it in /etc/xdg/autostart instead. I know they finally fixed Nautilus automatically starting in KDE using the OnlyShownIn setting. Changing files in this directory is system wide, so you may want to copy the file of the offending application to ~/.config/autostart/

Instead of using OnlyShownIn, you can also us NotShownIn. This can allow you to not something for the one desktop, but show it for all others. For this example, you can load Docky in all desktop managers except KDE, by using the following:

NotShownIn=KDE;

If you don't want it to start on any desktop, you can change it to OnlyShownIn=; Lines in .desktop files are supposed to end with a semicolon. The semicolon is also used to separate values for settings that take more than one value at the same time.

This trick would mean that you have to list every desktop shell you use to keep something from running at all. So using NotShownIn=Unity would be fine if you only have Unity installed, but it would still start if you later installed KDE or Gnome.

If the desktop file in your user autostart folder does not stop an application from starting, you will need to deal with the desktop file in the xdg directory. For this, I would make a backup copy of the file. Instead of copying it with a bak extension, or something standard that may get overwritten later do this for the imaginary application called badapp for this example.

sudo cp /etc/xdg/autostart/badapp.desktop /etc/xdg/autostart/badapp.desktop.stop

You may then edit the original desktop file. If something breaks and you end up starting in a text boot, you can then rename the file back to the original name.

sudo cp /etc/xdg/autostart/badapp.desktop.stop /etc/xdg/autostart/badapp.desktop

Also, the default user autostart folder for KDE is ~/.kde/Autostart/ because KDE does things the KDE way.