How to Autostart Applications in a WM on Arch Linux
Categories:
5 minute read
Arch Linux is a powerful, minimalist Linux distribution that gives users complete control over their system. One popular approach to customizing Arch Linux involves using a window manager (WM) instead of a full desktop environment (DE) like GNOME or KDE Plasma. Window managers are lightweight, fast, and minimalistic, but they often require manual configuration—especially when it comes to autostarting applications.
Autostarting applications is a common requirement for many users who want certain programs to run as soon as they log in. Examples include setting a wallpaper, launching a compositor, starting a status bar, or opening utilities like network managers and clipboard tools.
In this article, we’ll explore how to autostart applications in various window managers on Arch Linux. We’ll also cover some universal methods that work regardless of the WM you’re using.
Why Autostart Applications?
Before diving into the specifics, let’s understand the reasons you might want to autostart applications in your WM setup:
- Compositors (like
picom
orcompton
) for transparency, shadows, and animations. - Panel or status bar applications (like
polybar
,xmobar
, ortint2
). - Wallpaper setters (like
feh
ornitrogen
). - Network managers (
nm-applet
,connman-gtk
, etc.). - System tray applications (clipboards, battery monitors, etc.).
- Custom scripts for setting environment variables or other startup tasks.
While desktop environments typically have a centralized “autostart” directory or GUI settings panel, window managers usually require manual editing of configuration files.
Universal Methods of Autostarting Applications
1. Using .xinitrc
If you’re using startx to launch your graphical environment (common with minimal WMs), you likely have a ~/.xinitrc
file. This script is executed when startx
runs, and it’s an excellent place to autostart applications.
Example ~/.xinitrc
:
#!/bin/bash
# Set wallpaper
feh --bg-scale ~/Pictures/wallpaper.jpg &
# Start compositor
picom &
# Start network manager applet
nm-applet &
# Custom script
~/scripts/my_startup.sh &
# Start your WM
exec i3
Key points:
- Always end
.xinitrc
withexec your_wm
. - Use
&
to run commands in the background. - Ensure the file is executable:
chmod +x ~/.xinitrc
.
2. Using systemd User Services
Another advanced method is to use systemd user services. This method is desktop-agnostic and works well with both WMs and DEs.
Create a service, e.g., for nm-applet
:
mkdir -p ~/.config/systemd/user
Create the file ~/.config/systemd/user/nm-applet.service
:
[Unit]
Description=Network Manager Applet
[Service]
ExecStart=/usr/bin/nm-applet
Restart=always
[Install]
WantedBy=default.target
Enable and start the service:
systemctl --user enable nm-applet.service
systemctl --user start nm-applet.service
Make sure systemd --user
is available in your session. If you’re using startx
, you might need to add this to your .xinitrc
:
# Enable systemd user session
export XDG_RUNTIME_DIR=/run/user/$(id -u)
Autostarting in Specific Window Managers
1. i3 (Tiling WM)
i3 uses a configuration file located at ~/.config/i3/config
.
To autostart applications, use the exec
or exec_always
directive:
# ~/.config/i3/config
exec --no-startup-id feh --bg-scale ~/Pictures/wallpaper.jpg
exec --no-startup-id picom
exec --no-startup-id nm-applet
exec --no-startup-id volumeicon
exec
runs the application at startup.exec_always
runs it every time the config is reloaded (useful for bars or daemons).--no-startup-id
suppresses startup notifications.
2. Openbox (Stacking WM)
Openbox uses ~/.config/openbox/autostart
for startup programs.
Example:
# ~/.config/openbox/autostart
# Set wallpaper
nitrogen --restore &
# Compositor
picom &
# Network manager
nm-applet &
# Start panel
tint2 &
- The file is a shell script, so background your commands with
&
.
3. bspwm (Tiling WM)
Bspwm separates configuration into two files: bspwmrc
and sxhkdrc
.
Autostart applications in ~/.config/bspwm/bspwmrc
:
#!/bin/sh
# Start compositor
picom &
# Start panel
polybar example &
# Set wallpaper
feh --bg-fill ~/Pictures/wallpaper.jpg &
# Start network applet
nm-applet &
# Start window manager
exec bspwm
Make sure bspwmrc
is executable.
4. xmonad (Tiling WM in Haskell)
For xmonad, you modify the main
function in ~/.xmonad/xmonad.hs
.
Use spawn
within the startupHook
:
import XMonad
import XMonad.Util.SpawnOnce
myStartupHook = do
spawnOnce "feh --bg-scale ~/Pictures/wallpaper.jpg &"
spawnOnce "picom &"
spawnOnce "nm-applet &"
main = xmonad $ def
{ startupHook = myStartupHook
}
Then recompile:
xmonad --recompile
xmonad --restart
5. dwm (Dynamic WM in C)
With dwm
, you typically modify its source code. To autostart apps, edit dwm.c
or use an autostart
patch.
A quick workaround is to call a script from .xinitrc
before launching dwm
:
~/.config/dwm/autostart.sh &
exec dwm
Inside autostart.sh
:
#!/bin/sh
feh --bg-scale ~/Pictures/wall.jpg &
picom &
nm-applet &
Make it executable:
chmod +x ~/.config/dwm/autostart.sh
Tips and Best Practices
Use lightweight tools: WMs benefit from lightweight utilities like
feh
,picom
,volumeicon
, etc.Avoid launching duplicates: Use
pgrep
orpidof
to prevent multiple instances.pgrep nm-applet || nm-applet &
Log output: Redirect outputs to log files for debugging.
picom >> ~/.config/picom.log 2>&1 &
Centralize logic: Use a custom script to manage all autostarts and just call that script.
Watch for race conditions: Some applications may require a small delay to start after X has initialized.
(sleep 2 && nm-applet) &
Conclusion
Autostarting applications in a window manager on Arch Linux requires a bit of manual setup, but it gives you complete control over your environment. Whether you’re using i3, Openbox, bspwm, xmonad, or dwm, each WM has a preferred method for managing startup tasks. For users who want a more system-integrated approach, systemd user services provide a robust alternative.
This level of customization is exactly what makes using Arch Linux with a WM so rewarding—you build exactly what you need, from the ground up.
As always with Arch, the Arch Wiki is your best friend. Don’t forget to consult it regularly when you run into issues.
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.