You are not logged in.

#1 2009-04-25 19:44:15

rangalo
Member
Registered: 2008-06-25
Posts: 108
Website

Autostart programs in xmonad

Hi,

I want to start some programs in xmonad. I read that I have to write them in ~/.Xsession file. The problem is that they all wll be autostarted in my other WMs also. I am currently configuring / testing xmonad, so I don't want to affect the startup programs of other WMs I have. Is there any other way ?

regards,
Hardik

Offline

#2 2009-04-25 20:31:10

Stefan Husmann
Member
From: Germany
Registered: 2007-08-07
Posts: 1,391

Re: Autostart programs in xmonad

Use ~./xinitrc instead of ~/.Xsession. You can have a look at the .xsession of root for examples.

Offline

#3 2009-04-25 20:33:21

rangalo
Member
Registered: 2008-06-25
Posts: 108
Website

Re: Autostart programs in xmonad

will ~/.xinitrc start programs also for the other WMs (like fluxbox, openbox etc), I have ?

Offline

#4 2009-04-25 20:34:08

Arien
Member
Registered: 2009-04-23
Posts: 20

Re: Autostart programs in xmonad

You have at least two available options:
If you use Slim then it will send the session name as an argument to the .xinitrc/.xsession

which then can use the argument as follows to start apps depending on the session.

Edit: As an example my .xinitrc:

xmodmap .xmodmap
xsetroot -cursor_name left_ptr

##start terminal daemon #it requires no '&' at the end as it forks itself useing the -f switch
urxvtd -f -o -q

thunar --daemon&

xscreensaver -nosplash&

parcellite&
pidgin&
checkgmail&

#xcompmgr&

DEFAULT_SESSION=xmonad

case $1 in
xmonad)
    nitrogen --restore
    trayer --edge top --align right --expand true --SetDockType true --SetPartialStrut true --tint 0x000000 --alpha 0 --transparent true --height 17 --width 10 --margin 175&
    exec xmonad
    ;;
awesome)
    exec awesome
    ;;
*)
    nitrogen --restore
    trayer --edge top --align right --expand true --SetDockType true --SetPartialStrut true --tint 0x000000 --alpha 0 --transparent true --height 17 --width 10 --margin 175&
    exec $DEFAULT_SESSION
    ;;
esac

The other option would be to use the startupHook in your xmonad.hs. I am using the first method though, so best ask someone on the xmonad channel on freenode how to use the startuphook.

Have fun smile

Last edited by Arien (2009-04-25 20:34:51)

Offline

#5 2009-04-25 20:37:34

rangalo
Member
Registered: 2008-06-25
Posts: 108
Website

Re: Autostart programs in xmonad

Thanks Arien,

I am using kdm, does it send the session name as an argument ?

Offline

#6 2009-04-25 21:49:38

mikesd
Member
From: Australia
Registered: 2008-02-01
Posts: 788
Website

Re: Autostart programs in xmonad

I'm using a startup hook in xmonad to do a few things. You could also use it to start applications. The main reason I don't is that I edit my xmonad.hs daily and each time I restarted xmonad the applications would be launched again. There is probably a way around this though and it may not make any difference to you while testing. Anyways...

Add to your config:

startupHook        = startup

and then define the startup function:

startup :: X ()
startup = do
          spawn "xterm"
          spawn "xeyes"
          ...

the xmonad faq reccomends using .xinitrc for the above reason. More info here.

Last edited by mikesd (2009-04-25 21:54:02)

Offline

#7 2010-10-22 12:18:50

Digit
Member
Registered: 2008-04-28
Posts: 71

Re: Autostart programs in xmonad

surely there's a way to use startupHook, but also tell it to only launch the required if not already running?

i'm looking to autostart tilda & conky.

...could probably even do this with a bash script...

get startupHook to launch the script, and have the script take care of the if and else.

... if it cant be done from within the config that is.


fave quote of the mo': "Man's reach should exceed his grasp, else what's a heaven for." - Robert Browning

Offline

#8 2010-10-22 12:47:04

Knute
Member
From: Minot, ND
Registered: 2009-03-17
Posts: 604

Re: Autostart programs in xmonad

I have things starting in my startup hook, but found away around mucking with your xinitrc or xsession file so much.

In my $PATH I have added ~/bin to the works, then in ~/bin, I have a file that I call xmonad-autostart  (got the idea from awesome btw smile ).
Anyway, my xmonad-autostart has my programs that I want xmonad to start in the same format as xsession or xinitrc.   In my ~/.xinitrc file, I have added one line:

xmonad-autostart &

.  This line is right before the exec xmonad command.

Now, I start my X from the console,  If I remember right, there are options for the various wm's in the startup managers,  so all you would need would be to put your 'xmoand-autostart &' command in the then statement for xmoand.

HTH


Knute

Offline

#9 2010-10-22 13:15:41

Digit
Member
Registered: 2008-04-28
Posts: 71

Re: Autostart programs in xmonad

well, a little fiddling n i think i've got mine sorted.

smile

yet to restart xmonad to test though...

couple scripts to start each app.

using sox, i quickly did a "rec sounds/tildarunning.wav" and "rec sounds/conkyrunning.wav" speaking into the mic "tilda is already running" and "conky is already running"  ... just to add some fun to it.  (will probably remove this when it gets annoying after a few restarts)

#! /bin/bash
if [ "$(ps -C conky | tail --bytes=6)" = "conky" ]; then
play ~/sounds/conkyrunning.wav
else
conky
fi

# alternative methods suggested by guys in #bash on freenode
# if pgrep conky >/dev/null; then ...
# also said was:
# You possibly want -u "$USER" too

&

#! /bin/bash
if [ "$(ps -C tilda | tail --bytes=6)" = "tilda" ]; then
play ~/sounds/tildarunning.wav
else
tilda
fi

# alternative methods suggested by guys in #bash on freenode
# if pgrep tilda >/dev/null; then ...
# also said was:
# You possibly want -u "$USER" too

~edit
FAIL!   XD   still needs some work.  XD
this inspired me to add a new line to my signature. 
fave quote of the mo': "Man's reach should exceed his grasp, else what's a heaven for." - Robert Browning
... better to look a fool while trying, than to stay with noobuntu.  wink

Last edited by Digit (2010-10-22 16:41:00)


fave quote of the mo': "Man's reach should exceed his grasp, else what's a heaven for." - Robert Browning

Offline

#10 2010-10-22 13:29:41

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

Re: Autostart programs in xmonad

ugly! tongue

import XMonad.Actions.WindowGo (runOrRaise)

--
-- with startupHook = startup
--
-- this is totally untested but i guess startup just needs to be :: X ()
-- which runOrRaise also happens to return...
startup :: X ()
startup = do
    runOrRaise <String executable> (<Query Bool to find it>)
    runOrRaise "chromium" (className =? "Chromium")
    runOrRaise ...

This will run them if they're not there, or (I think) bring them into focus if they are.  This may or may not be what you want, but you could probably hack the source for runOrRaise to prevent the raiseHook from running (which would leave the window where it was), call it runOrNot...

You can use xprop to find the class name of the the apps you want.  any thing you can use in a manageHook can be used here.

Offline

#11 2010-11-10 06:10:57

Inxsible
Forum Fellow
From: Chicago
Registered: 2008-06-09
Posts: 9,183

Re: Autostart programs in xmonad

Digit, start new threads, link to old ones. Read forum rules and please abide by them.

Closing...


Forum Rules

There's no such thing as a stupid question, but there sure are a lot of inquisitive idiots !

Offline

Board footer

Powered by FluxBB