I’ve been having problems with nm-applet that crashes on a regular basis lately. Apparently I’m not the only one, but it’s not often enough to do anything about it apart form restarting it when it drops off the system tray.

I got tired of doing it by hand, so I got i3 to do it for me of course 🙂

If you too need to start a program at login and keep restarting it if it stops, you might find this little trick useful:

In case you didn’t know, exec and exec_always in the i3 config file don’t directly call an executable, but rather execute the command in a shell. So naturally, you can run an inline shell script rather than a single command.

So in my case, instead of this line in my i3 config file:

exec --no-startup-id nm-applet

I have this line:

exec --no-startup-id while [ 1 ]; do nm-applet; sleep 0.2; done

The latter is a one-liner equivalent of running the following shell script inside the shell that i3 calls to run the argument of exec:

while [ 1 ]; do
  nm-applet
  sleep 0.2
done

This script will run nm-applet in a loop forever. The sleep delay is just there to throttle the script and avoid killing the CPU if nm-applet fails to start altogether for some reason.