AwesomeWM XDG Autostart
Out of the box AwesomeWM does not provide a mechanism for automatically starting applications when it starts. I have a small piece of code in my configuration file to do this however it is sub-optimal, not least because (despite using awful.spawn.once
it relaunches all of the applications on restart. Instead I applied a snippet from Arch Linux’s Wiki’s page on AwesomeWM that autostarts applications using the XDG Autostart Specification.
The original code is this:
--- {{{ Autostart
local autorun = true
local autorunApps = {
"/usr/bin/keepassxc",
"/usr/bin/bash -c 'QT_AUTO_SCREEN_SCALE_FACTOR=1 /usr/bin/nextcloud'",
"/usr/bin/solaar -w hide",
}
if autorun then
for app = 1, #autorunApps do
-- spawn.once will not respawn if Awesome is restarted via awesome.restart()
-- 2nd argument is only non-optional until https://github.com/awesomeWM/awesome/pull/2716
-- once Debian version is updated, should remove that.
awful.spawn.once(autorunApps[app], {})
end
end
--- }}}
and the new code:
awful.spawn.with_shell(
'if (xrdb -query | grep -q "^awesome\\.started:\\s*true$"); then exit; fi;' ..
'xrdb -merge <<< "awesome.started:true";' ..
'if [ -z "$XDG_CONFIG_HOME" ]; then XDG_CONFIG_HOME="$HOME/.config" fi;' ..
'if [ -z "$XDG_CONFIG_DIRS" ]; then XDG_CONFIG_DIRS="/etc/xdg"; fi;' ..
'DEX_SERACH_PATHS="$( echo "$XDG_CONFIG_DIRS" | sed s#:#/autostart# )/autostart:$XDG_CONFIG_HOME/autostart";' ..
-- list each of your autostart commands, followed by ; inside single quotes, followed by ..
'dex --environment Awesome --autostart --search-paths "$DEX_SERACH_PATHS"' -- https://github.com/jceb/dex
)
I then did not have to create any desktop entries - it turned out all of the applications I wanted to automatically start already had autostart entries.