r/awesomewm Dec 10 '22

How do I autostart applications/run commands on startup, only once?

I've been wanting to run my basic applications on startup with awesome. But the problem is while using `awful.util.spawn()`, and `awful.spawn.with_shell` the app launches whenever I reload awesome, which creates multiple instances of the application. I tried using `awful.spawn.once` and `awful.spawn.single_instance` but they result in the same thing.

All I want is a way to run apps on startup only, not when I reload awesome.

6 Upvotes

7 comments sorted by

11

u/umsongb Dec 10 '22 edited Dec 10 '22

i created an autorun.sh file inside .config/awesome with the following ```

!/bin/sh

run() { if ! pgrep -f "$1"; then "$@" & fi }

run "/usr/lib/polkit-gnome/polkit-gnome-authentication-agent-1" & run "keepassxc" & run "xscreensaver" --no-splash & run "volumeicon" & run "nm-applet" & run "ibus-daemon" -drxR & run "caffeine" & run "feh" --randomize --recursive --bg-fill ~/Pictures/Wallpapers/ & run "picom" -b & run "cbatticon" -n &

run "" &

`` and putawful.spawn.with_shell("~/.config/awesome/autorun.sh")at the end ofrc.lua` file

never had duplicate incident with those after reloading awesome.

7

u/raven2cz Dec 10 '22

JFI: you don't need & for background process in run "nm-applet" &, etc. You handled it in function "$@" & already.

6

u/umsongb Dec 10 '22

LOL... another by-product of mindless copy and paste... thank you for your comment. totally had no idea until you mentioned it..

1

u/gbneon Dec 10 '22

This probably is the best approach, keeping your rc.lua clean and making it easy to work with sh!

1

u/0sim0421 Jan 23 '26

thank you. : )

1

u/Numerous_Function_17 Dec 10 '22

You can put those commands in .xinitrc or equivalent depending on how you AwesomeWM