Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
HOWTO: Auto Start programs on login via GDM
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
smarm
n00b
n00b


Joined: 10 Jan 2003
Posts: 36

PostPosted: Mon Aug 02, 2004 4:43 am    Post subject: HOWTO: Auto Start programs on login via GDM Reply with quote

Lately I've been trying to start a variety of programs on logging into my Gnome session. Needless to say its been an immense hastle trying to find out exactly how to do it. So I've compiled here my solution to the problem; as well as the numerous other methods I discovered and attempted on the way to my solution. I list the failed attempts as they will (hopefully!) redirect others who are following my misguided methods in search of a solution.

Initially I sought a way to execute a script as I was logging in via GDM. The numerous methods I found failed to work. .xinitrc, .xsession, .bash_profile, startup and .bashrc all failed to work in some fashion or another. Documented here:

Best way to auto start a program -
https://forums.gentoo.org/viewtopic.php?t=198201

starting applications during X.. how? -
https://forums.gentoo.org/viewtopic.php?t=195934

Starting apps on X startup with GDM -
https://forums.gentoo.org/viewtopic.php?t=189739

It wasn't until I came upon this thread:

~/.xinitrc quick question -
https://forums.gentoo.org/viewtopic.php?t=203258

That I found my first inkling that the traditional methods might be rendered null with the new version of Gnome. The next pertinent thread I found seemed to deal with my exact problem:

Fixing new sessions with GDM 2.6 -
https://forums.gentoo.org/viewtopic.php?t=162521

This did not work precisely as advertised either. As you can see from this code:
Code:

#!/bin/bash
exec xmodmap -e "pointer = 1 2 3 6 7 4 5" &
exec imwheel -p -k -b "000067" -f &
xfce-mcs-manager &
perlpanel &
openbox


furiorc attempts to open some programs then start his window manager (openbox), this of course does not work with Gnome. There is no simple "gnome" command that can be executed to start a gnome session. Further in the thread I discovered a partial solution:

Code:

#!/bin/bash                                                               
#Chinese Input Method
export XMODIFIERS="@im=SCIM" &
export XIM=scim &
export XIM_PROGRAM=scim &
scim -d &                                       
gnome-session


furiorc calls the startup script for gnome, namely gnome-session. Which is what is originally called in my "/usr/share/xsessions/gnome.desktop." The problem with this script is that it does not check if the programs called are already running. My final solution came as a piece of another less helpful post, namely from the thread "Best way to auto start a program." In it sapphirecat demonstrates a bash script that does checking for an instance of the program to be started:

Code:

# (Sourced by .xsession and .bash_profile)
if ! ps -u $USER | cut -b 25- | grep '^irexec$' &>/dev/null
then
irexec --daemon
fi


Of course a more general solution would be:

Code:

#!/bin/bash
if !(ps -u $USER |  cut -b 25- |  grep (command to be executed) >/dev/null)
then
(stuff you want to execute)
fi
(your x-session)


This simple script lists all processes owned by your user ($USER global variable), cuts off all texts before the process names, the searches the remaining text for the command you want to execute and sends the results to the bit bucket (null's the output of grep). If the process you've searched for is not currently active the execution commands will run.

To sum up:

In "/usr/share/xsessions/" should be a script that is named "something".desktop ("something" will vary depending on your window manager). Log in as root and make your own, of the format:

Code:

[Desktop Entry]
Encoding=UTF-8
Name=(whatever name you like)
Comment=(some comment)
Exec=(the name of your custom bash script, I used My_Gnome_Session)
TryExec=(again the custom bash script name)
Icon=
Type=Application


Now make a file (still as root) in "/usr/bin/", eg My_Gnome_Session. Change the permissions on your new custom script so you can execute it:

Code:

chmod 755 (custom script name)


("custom script name" should match the "Exec=" command in your custom desktop script)

Edit it with your favorite text editor. Add this bash script:

Code:

#!/bin/bash
if !(ps -u $USER |  cut -b 25- |  grep (command to be executed) >/dev/null)
then
(stuff you want to execute)
fi
(your x-session)


Replace "command to be executed" with the process you want to search for, to make sure it isn't execute twice. Change "stuff you want to execute" to the command(s) you want to run. Change "your x-session" to the script that the original desktop file in "/usr/share/xsessions/" executed. For example my /usr/share/xsessions/gnome.desktop executed a program called "gnome-session". If in doubt search for the line prefaced by "Exec=" in your original desktop script.

Of course multiple if's can be used to check for multiple programs, always remeber to add the x-session at the very end of the script. Also you may need to preface some of your execution commands with "exec". Or you may need to add an '&' at the end of a command to "daemonize" it, or spin it off into its own independent process.

I hope this has been of help.

smarm
Back to top
View user's profile Send private message
michaelkuijn
n00b
n00b


Joined: 28 Sep 2003
Posts: 72
Location: The Netherlands

PostPosted: Mon Aug 30, 2004 11:41 am    Post subject: Reply with quote

Thanks! I have been searching for elegant ways to start xmodmap, imwheel and irexec for quite some time. Your post was very helpful.
Back to top
View user's profile Send private message
pi-cubic
Tux's lil' helper
Tux's lil' helper


Joined: 25 May 2003
Posts: 143

PostPosted: Sun Sep 12, 2004 6:28 pm    Post subject: Reply with quote

thanks for the nice howto first!

but i do have some problems:
one of my startup-commmands is:
Code:
xmodmap $HOME/.Xmodmap &

my .Xmodmap contains all my personal keycodes (personal keyboard layout). but it's not going to be executed. why that?

greetings,

pi
Back to top
View user's profile Send private message
torklingberg
Tux's lil' helper
Tux's lil' helper


Joined: 30 May 2004
Posts: 86

PostPosted: Sat Oct 23, 2004 12:28 pm    Post subject: Reply with quote

In my /usr/share/xsessions/gnome.desktop these lines already exist:
Code:
Exec=gnome-session
TryExec=gnome-session


/usr/bin/gnome-session is a binary file.

Should I add two more Exec= and TryExec= lines or what?
Back to top
View user's profile Send private message
rm
Tux's lil' helper
Tux's lil' helper


Joined: 25 Oct 2004
Posts: 87

PostPosted: Fri Nov 12, 2004 9:45 pm    Post subject: Reply with quote

There is a nice graphical way to do it:

Code:
Applications
  -> Desktop Preferences
         -> Advanced
                -> Sessions


for the moment, the only thing I start up is x11-misc/numlockx.

bye,
rm
Back to top
View user's profile Send private message
torklingberg
Tux's lil' helper
Tux's lil' helper


Joined: 30 May 2004
Posts: 86

PostPosted: Fri Nov 12, 2004 9:54 pm    Post subject: Reply with quote

Yes, just make sure to set "Order" to 0, since high numbers there will cause gnome not to start properly. I don't really know why.
Back to top
View user's profile Send private message
monotux
l33t
l33t


Joined: 09 Sep 2003
Posts: 751
Location: Stockholm, Sweden

PostPosted: Fri Nov 12, 2004 9:57 pm    Post subject: Reply with quote

I still think my solution is muuuuuch better :wink: :D
_________________
Computer science is no more about computers than astronomy is about telescopes.
Back to top
View user's profile Send private message
rm
Tux's lil' helper
Tux's lil' helper


Joined: 25 Oct 2004
Posts: 87

PostPosted: Sat Nov 13, 2004 8:27 am    Post subject: @torklingberg Reply with quote

The order for numlockx is set to 50 for me.
Working allrightie :D

bye
rm
Back to top
View user's profile Send private message
VinzC
Watchman
Watchman


Joined: 17 Apr 2004
Posts: 5030
Location: Dark side of the mood

PostPosted: Tue Feb 01, 2005 8:16 pm    Post subject: Reply with quote

torklingberg wrote:
Yes, just make sure to set "Order" to 0, since high numbers there will cause gnome not to start properly. I don't really know why.

Since I upgraded to Gnome 2.8 I couldn't launch numlockx with an Order set to less than 50. In fact Gnome stops at loading nautilus state (while Gnome splash is displayed) if I setup Order to less than 50. There's no way out but Ctrl+Alt+BkSpace.

I've tried 25, 35, 40 and 45. If I set it to 55 it works but then gdesklets take more than one minute to show up on my desktop :(.

I now think numlockx is the real messy thing.
_________________
Gentoo addict: tomorrow I quit, I promise!... Just one more emerge...
1739!
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum