Purpose: Let’s say you want to execute a command or a script automatically every time you log into your GDM/GNOME environment. How do you do that? There is no intuitive way currently to do that. So let’s get started…


I am assuming that you have already installed GDM and GNOME on your system.

# apt-get install gdm gnome

Step 1: Identify your command

Let’s say you like to run the following command every time you boot into GNOME environment.

# set s off -dmps

which basically disables your screen blanking and energy star monitor settings.

Step 2: Create .xsession file

nano .xsession

and add the following contents:

x set s off -dmps &
exec gnome-session

Save and quit the file.

Step 3: Configure GDM

Now you need to tell your GDM login manager to source the .xsession script whenever you log in.

Logout of your GNOME session and when you are presented with the GDM screen click on “Sessions->Run XClient Script” as your session. When you try to log in it will ask you whether you want to make this setting as permanent (default session) or you want only for this session. If you are trying to execute the command always than just make that a default session.

Step 4: Verify your result

Finally upon logging into your GNOME session you will notice that the command has execute successfully. You can verify your result by giving the following command:
# xset s

Additional Notes

You can a step further and configure your GDM to auto-login as you so ways next time when you restart your system you will straight away go into your GNOME desktop and the command will be execute in the background automatically for you.

That’s it! Happy GDM’ing!

Be Sociable, Share!