I want to execute some commands after login if awesome-windowmanager starts. How can I add startup-commands to the awesome-config?
4 Answers
According to this ArchLinux wiki you should just need to add the following to your rc.lua
:
-- Autorun programs
autorun = true
autorunApps =
{
"swiftfox",
"mutt",
"consonance",
"linux-fetion",
"weechat-curses",
}
if autorun then
for app = 1, #autorunApps do
awful.util.spawn(autorunApps[app])
end
end
The wiki also show a couple of other ways to achieve the same effect.
-
7What happens when you reload awesome? Is autorun set to false later in the config?– lkraavAug 22, 2011 at 21:51
-
1
-
1you can't actually detect this, even when abusing the globals table like it's done by accident in the example above. awesome reload wipes the lua vm. do something like running "pgrep firefox || firefox" for example instead.– nonchipMar 20, 2018 at 20:31
-
1or actually do it like the wiki suggests, since it seems to have been fixed (and the broken code above removed)– nonchipMar 20, 2018 at 20:33
I am going with dex, so far.
$ cat /etc/X11/Sessions/awesome
#!/bin/sh
# Awesome Xsession starter, based on Xsession shipped by x11-apps/xinit-1.0.5-r1
...
zenity --title "Autostart" --timeout=30 --question --text="Launch autostart items?" && dex -a
exec ck-launch-session /usr/bin/awesome
Let's have some autostart items too then:
$ ls -1 ~/.config/autostart/
gol.desktop
KeePass 2.desktop
skype-skype.desktop
tomboy.desktop
wpa_gui-wpa_supplicant.desktop
xterm-logs.desktop
Example autostart item:
$ cat ~/.config/autostart/gol.desktop
[Desktop Entry]
Type=Application
Terminal=false
Name=Growl For Linux
Comment=Growl Desktop Notification System For Linux
Categories=GNOME;GTK;Utility;
Exec=/usr/bin/gol
Icon=/usr/share/growl-for-linux/data/icon.png
X-GNOME-Autostart-enabled=true
X-KDE-autostart-after=panel
X-Desktop-File-Install-Version=0.18
The Awesome wiki suggests this way that will work when reloading Awesome.
Put this in runonce.lua
-- @author Peter J. Kranz (Absurd-Mind, [email protected])
-- Any questions, criticism or praise just drop me an email
local M = {}
-- get the current Pid of awesome
local function getCurrentPid()
-- get awesome pid from pgrep
local fpid = io.popen("pgrep -u " .. os.getenv("USER") .. " -o awesome")
local pid = fpid:read("*n")
fpid:close()
-- sanity check
if pid == nil then
return -1
end
return pid
end
local function getOldPid(filename)
-- open file
local pidFile = io.open(filename)
if pidFile == nil then
return -1
end
-- read number
local pid = pidFile:read("*n")
pidFile:close()
-- sanity check
if pid <= 0 then
return -1
end
return pid;
end
local function writePid(filename, pid)
local pidFile = io.open(filename, "w+")
pidFile:write(pid)
pidFile:close()
end
local function shallExecute(oldPid, newPid)
-- simple check if equivalent
if oldPid == newPid then
return false
end
return true
end
local function getPidFile()
local host = io.lines("/proc/sys/kernel/hostname")()
return awful.util.getdir("cache") .. "/awesome." .. host .. ".pid"
end
-- run Once per real awesome start (config reload works)
-- does not cover "pkill awesome && awesome"
function M.run(shellCommand)
-- check and Execute
if shallExecute(M.oldPid, M.currentPid) then
awful.util.spawn_with_shell(shellCommand)
end
end
M.pidFile = getPidFile()
M.oldPid = getOldPid(M.pidFile)
M.currentPid = getCurrentPid()
writePid(M.pidFile, M.currentPid)
return M
Use it this way:
local r = require("runonce")
r.run("urxvtd -q -o -f")
r.run("urxvtc")
r.run("urxvtc")
r.run("wmname LG3D")
ArchWiki Approach
For newer users, in the ArchWiki you can find that you need to:
- create
~/.config/awesome/autorun.sh
and add
#!/usr/bin/env bash
function run {
if ! pgrep -f $1 ;
then
$@&
fi
}
run
checks with the process grep (so you don't re execute the process), and puts the bins straight into the background.
In the ~/.config/awesome.rc.lua
tell it to spawn that file with the shell (bash or whichever you set). You do it like so (last line in file):
awful.spawn.with_shell("~/.config/awesome/autorun.sh")
Simpler Approach
Now for me, with many arguments the pgrep was a bit picky. So I wrote a simpler, good for my use at least, script. This is my autorun.sh
:
#!/usr/bin/env bash
feh --bg-scale $(ls ${HOME}/wallpaper/*.png|shuf -n1) &
nm-applet &