Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Discussion & Documentation Documentation, Tips & Tricks
  • Search

HOWTO: Auto Start programs on login via GDM

Unofficial documentation for various parts of Gentoo Linux. Note: This is not a support forum.
Post Reply
Advanced search
9 posts • Page 1 of 1
Author
Message
smarm
n00b
n00b
Posts: 36
Joined: Fri Jan 10, 2003 1:06 am

HOWTO: Auto Start programs on login via GDM

  • Quote

Post by smarm » Mon Aug 02, 2004 4:43 am

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 -
http://forums.gentoo.org/viewtopic.php?t=198201

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

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

It wasn't until I came upon this thread:

~/.xinitrc quick question -
http://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 -
http://forums.gentoo.org/viewtopic.php?t=162521

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

Code: Select all

#!/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: Select all

#!/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: Select all

# (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: Select all

#!/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: Select all

[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: Select all

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: Select all

#!/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
Top
michaelkuijn
n00b
n00b
User avatar
Posts: 72
Joined: Sun Sep 28, 2003 3:15 pm
Location: The Netherlands

  • Quote

Post by michaelkuijn » Mon Aug 30, 2004 11:41 am

Thanks! I have been searching for elegant ways to start xmodmap, imwheel and irexec for quite some time. Your post was very helpful.
Top
pi-cubic
Tux's lil' helper
Tux's lil' helper
User avatar
Posts: 143
Joined: Sun May 25, 2003 5:06 pm

  • Quote

Post by pi-cubic » Sun Sep 12, 2004 6:28 pm

thanks for the nice howto first!

but i do have some problems:
one of my startup-commmands is:

Code: Select all

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
Top
torklingberg
Tux's lil' helper
Tux's lil' helper
User avatar
Posts: 86
Joined: Sun May 30, 2004 12:36 pm

  • Quote

Post by torklingberg » Sat Oct 23, 2004 12:28 pm

In my /usr/share/xsessions/gnome.desktop these lines already exist:

Code: Select all

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?
Top
rm
Tux's lil' helper
Tux's lil' helper
Posts: 87
Joined: Mon Oct 25, 2004 9:38 pm

  • Quote

Post by rm » Fri Nov 12, 2004 9:45 pm

There is a nice graphical way to do it:

Code: Select all

Applications
  -> Desktop Preferences
         -> Advanced
                -> Sessions
for the moment, the only thing I start up is x11-misc/numlockx.

bye,
rm
Top
torklingberg
Tux's lil' helper
Tux's lil' helper
User avatar
Posts: 86
Joined: Sun May 30, 2004 12:36 pm

  • Quote

Post by torklingberg » Fri Nov 12, 2004 9:54 pm

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.
Top
monotux
l33t
l33t
User avatar
Posts: 751
Joined: Tue Sep 09, 2003 4:18 pm
Location: Stockholm, Sweden
Contact:
Contact monotux
Website

  • Quote

Post by monotux » Fri Nov 12, 2004 9:57 pm

I still think my solution is muuuuuch better :wink: :D
Computer science is no more about computers than astronomy is about telescopes.
Top
rm
Tux's lil' helper
Tux's lil' helper
Posts: 87
Joined: Mon Oct 25, 2004 9:38 pm

@torklingberg

  • Quote

Post by rm » Sat Nov 13, 2004 8:27 am

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

bye
rm
Top
VinzC
Watchman
Watchman
User avatar
Posts: 5100
Joined: Sat Apr 17, 2004 1:51 pm
Location: Dark side of the mood

  • Quote

Post by VinzC » Tue Feb 01, 2005 8:16 pm

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!
Top
Post Reply

9 posts • Page 1 of 1

Return to “Documentation, Tips & Tricks”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy

 

 

magic