Running applications automatically when X starts

Posted by Steve on Thu 2 Dec 2004 at 19:45

The majority of people who use Debian upon the desktop launch straight into the X11 Window system, usually via one of the choosers xdm, gdm, or kdm. Once you've entered your username and password you get your Window Manager running and are ready to start work. But what if you want a program or two to start as soon as you login?

The bigger desktop environments such as KDE or GNOME have their own facilities for starting programs when they load up.

In the case of KDE you simply place a shellscript, or symbolic link to an executable, into a special startup directory:

/home/username/.kde/Autostart

This will be executed at login time.

For GNOME you can use the control center. Go to the Control Center and select the sessions option. Inside there use the Session Properties & Startup section to choose the 'Startup Programs' tab. This allows you to add new programs to run at startup.

But what about causing programs to run if you're not running those environments?

Well the choosers gdm, kdm and xdm all support a standard startup system.

These choosers use XSession to run programs either globally or per-user when you login.

The global options are suitable if you wish to run a program for any user who logs into your machine, the per-user settings only apply to yourself.

Global options are the simplest ones. Simple place a shell script (make it executable) into the directory /etc/X11/Xsession.d

The files in the Xsession.d are executed in the order they are found - which explains why you might find some scripts located there already with numbers in their names.

I almost always want to have a terminal open and the music player xmms running when I login. I can achieve this by saving following shell script as /etc/X11/Xsession.d/startup-local

#!/bin/sh

xmms &

xterm &

Make it executable with:

chmod 755 /etc/X11/Xsession.d/startup

Notice that you must put the commands to run in the background? If you don't do that then your window manager will not start until after those programs have exitted.

If you just want to do this for yourself you can achieve the same thing by saving the script to run as ~/.xsession:

#!/bin/sh

xmms &

xterm &

(Again making it executable).

This is the per-user configuration file and will only affect you.

Either of these systems allow you to start programs automatically with the leighter weight Window Managers such as my personal favorite IceWM.

 

 


Posted by Anonymous (127.0.xx.xx) on Fri 3 Dec 2004 at 03:51

I know this is off topic but I really just want to say thank you for the articles. I have only been running my own server for a few months, which is when I started using Debian. And there are just lots of little things that this site has helped to point out. Nathan Bullock

[ Parent | Reply to this comment ]

Posted by Anonymous (127.0.xx.xx) on Tue 21 Dec 2004 at 04:03
Just one additional note. Some window managers like Enlightenment have

[ Parent | Reply to this comment ]

Posted by Anonymous (195.146.xx.xx) on Fri 31 Dec 2004 at 14:59
For Icewm, there is simply the script ~/.icewm/startup (make it executable of course) Mokoshi

[ Parent | Reply to this comment ]

Posted by Anonymous (201.243.xx.xx) on Sat 21 May 2005 at 18:22
It doesn't work on Debian Sarge (i use gnome)

i do the following: vim ~/.xsession

and in the file i write:

#!/bin/sh

gaim &

(i want gaim initiate when i enter in X)

But then when i login it gives me an error that my last session has dured less than 10 secods and it get outs the session

[ Parent | Reply to this comment ]

Posted by Anonymous (134.84.xx.xx) on Fri 10 Jun 2005 at 16:27
If you have a .xsession file your session will only last as long as that process lives. When the script ends you are considered logged out so you should have a line at the end of your .xsession script like "exec icewm" (or whichever window manager you're using). This will pass off the process to the window manager which will hold your session open as long as it's running.

[ Parent | Reply to this comment ]

Posted by Anonymous (62.179.xx.xx) on Tue 25 Oct 2005 at 19:21
With my IceWM and gdm neither .xsession nor starup scripts are working. I bored with this. I read dozens of manuals, forums and articles. Everyone says something else but none of theese methods is working on my machine. I just want to start an screensaver and xterm on starup.
Any diffrent methods of running? Someone could help me?

[ Parent | Reply to this comment ]

Posted by Anonymous (212.238.xx.xx) on Mon 21 Nov 2005 at 17:07
Make sure use the Default Session in gdm. It helped for me...

[ Parent | Reply to this comment ]

Posted by Anonymous (130.133.xx.xx) on Thu 1 Dec 2005 at 10:45
AFAICS your .xsession script will never be started. Here's what happens:

- gdm calls /etc/gdm/Xsession
- XSession sources a whole buch of scripts in /etc/X11/Xsession.d
- one of them is called 50xfree86-common_determine-startup

So what does this script do?

It checks if an argument was passed to the Xsession script (by gdm), and only if NO argument was passed to the Xsession script (and the appropriate Option is set in /etc/X11/Xsession.options), it will execute the user defined session script (~/.xsession).

[ Parent | Reply to this comment ]

Posted by Anonymous (200.122.xx.xx) on Wed 19 Apr 2006 at 01:37
Not so long ago you could choose a session that read your ~/.xsession (I don't remember the name). A quick workaround is to choose a different session, log in, edit ~/.dmrc and change the "Session=foo" line to "Session=custom". According to the comments at the beginning of /etc/gdm/Xsession, a 'custom' session will run your ~/.xsession. I could not find when this changed.

hope this helps.

[ Parent | Reply to this comment ]

Posted by phantomlord (82.199.xx.xx) on Wed 8 Nov 2006 at 22:46
[ Send Message ]
I'm trying to make xbindkeys to run when Enlightenment starts, but something is not write. It just doesn't. Here is what I do:

nano /etc/X11/Xsession.d/xbindkeys

I put there:

#!/bin/sh

xbindkeys &

And I make:

sudo chmod 755 /etc/X11/Xsession.d/xbindkeys

Just in case, I do:

/etc/init.d/gdm stop
/etc/init.d/gdm start

But when I log-in to Enlightenment xbindkeys is not loaded.
Does anybody have an idea what is the reason?

10x

[ Parent | Reply to this comment ]

Posted by justr (217.244.xx.xx) on Thu 21 Sep 2006 at 08:05
[ Send Message ]
Now we now how to start applications when the user's desktop is started.
E.g. vmware needs to run it's toolbox as root to be somehow useful. Now I want to load the toolbox automatically when the user's XFCE4's desktop is started. How to do that? Problem is that this should run without user interference...

[ Parent | Reply to this comment ]

Posted by Anonymous (201.250.xx.xx) on Sat 25 Nov 2006 at 14:00
Thanks..... but I have a similar problem but i can´t use de same solution..Can you tell me hay can I meke de same but with a doc such us mp3 or avi...?

[ Parent | Reply to this comment ]

Sign In

Username:

Password:

[Register|Advanced]

 

Flattr

 

Current Poll

Which init system are you using in Debian?






( 1637 votes ~ 7 comments )