I'm using Ubuntu Mate with XMonad. I can't seem to understand how to run something at startup after the login.

I want some programs like Firefox to run when I login to my desktop.

Now let's say I just want to run a simple script:


The file is set as executable.

I've tried many things. Startup Applications from Ubuntu Mate settings are obviously not working on xmonad.

The second thing I've tried was putting the command at the end of my .xsessionrc file, after xmonad is executed. My .xsessionrc file:


xrdb -merge .Xresources
stalonetray &
feh --bg-scale /usr/share/backgrounds/cosmos/sombrero.jpg &
udiskie &
xfce4-power-manager &
xrandr --auto --output HDMI-1 --primary --left-of VGA-1 &
# Firefox PulseAudio fix
pulseaudio --start --exit-idle-time=-1 &
compton -bCG --active-opacity 1.0 --shadow-ignore-shaped &
if [ -x /usr/bin/nm-applet ] ; then
   nm-applet --sm-disable &
exec xmonad
exec /home/juser/.xmonad/autostart.sh  #THIS IS NOT WORKING

The desktop starts successfully but my script is not executed.

Another thing that doesn't work is to use SpawnOnce inside xmonad.hs file. Something like that ( I've pasted my entire file here: https://pastebin.com/yUXjbgva ):

import XMonad.Util.SpawnOnce

myConfig = docks defaultConfig
        , startupHook = myStartupHook

myStartupHook = do
    spawnOnce "/home/juser/.xmonad/autostart.sh"

My script is simply ignored same as in previous example. So I gave up on SpawnOnce directive.

Do I have any other options? What am I doing wrong?


The line exec xmonad in your shell script replaces the shell running the script with the xmonad process. So there's nobody left to run the next line. Type help exec in a bash shell, or see bash(1).

You probably want to rewite the last two lines as

/home/juser/.xmonad/autostart.sh &
exec xmonad

if none of the autostarted stuff needs xmonad.

  • Thanks. This explains why my first example doesn't work. Sadly I think I do need xmonad first before my autostart.sh. For example: I will put firefox into that file, so it should be called after xmonad has already loaded, right? So is there any other way? I can't believe that applications like Firefox cannot be autostarted in xmonad.
    – user568021
    Nov 18 '18 at 15:44
  • Hm.. But if I put something like "sleep 6" before the script starts firefox it works (because xmonad already loads withing these 6 seconds). I can accept your answer, but this doesn't seem the most elegant way of autostarting something. Thanks for your help!
    – user568021
    Nov 18 '18 at 15:54
  • Hmm, I'm not using Xmonad. Independent of the WM though, I'd use exec launch-my-wm (whatever that would be) as the last line, because termination of the WM should (I guess) terminate the session. Things that depend on the WM should be started by the WM. I've been applying these concepts to FVWM or Openbox.
    – stefan
    Nov 19 '18 at 17:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.