Run a command when i3 exits?
Hi, I know you can use "exec" in your i3 config file to run something when you log in, but is there any way to have it run something when you sign out?
Hi, I know you can use "exec" in your i3 config file to run something when you log in, but is there any way to have it run something when you sign out?
You can do this with the new i3ipc library (Python, Lua, JavaScript)
#!/usr/bin/env python3
from gi.repository import i3ipc
def on_shutdown(conn):
print('goodbye, world')
conn = i3ipc.Connection()
conn.on('ipc_shutdown', on_shutdown)
conn.main()
The event will fire whenever the connection to the ipc is lost (including on i3-msg restart
) and the main loop will end afterwards.
Now put this line in your config:
exec_always --no-startup-id ~/bin/i3-shutdown.py
This should give you the general idea.
bindsym $mod+e mode "Exit"
# Exit i3 in various ways.
mode "Exit" {
bindsym h exec gksu "/sbin/shutdown -h now"
bindsym r exec gksu "/sbin/shutdown -r now"
bindsym x exit
# back to normal: Enter or Escape
bindsym Return mode "default"
bindsym Escape mode "default"
}
Asked: 2014-03-03 22:44:51 +0000
Seen: 413 times
Last updated: Mar 15 '14