The i3 FAQ has migrated to https://github.com/i3/i3/discussions. All content here is read-only.
Ask Your Question
1

How to close all open programs in terminal

asked 2014-11-09 12:28:30 +0000

Ali gravatar image

updated 2014-11-12 13:08:35 +0000

Adaephon gravatar image

I use this command for shutdown in i3:

systemctl poweroff

I have 4 workspaces with these apps: firefox, terminal, ncmpcpp and nautilus and I want to close all these (and other open) programs before I call the systemctl poweroff command.

Is there a command or script that could do this?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2014-11-10 09:58:35 +0000

Adaephon gravatar image

updated 2014-11-11 06:23:08 +0000

[class=".*"] kill

this will run the i3 command kill on every window. This includes the i3-bar, but as you are going to shut down anyway that should not be a problem.

You can just bind it to a shortcut:

bindsym Mod4+Mod1+q [class=".*"] kill

It is possible to chain the kill command with the exit command on the same shortcut. But I would advise against it, as kill does not wait until the windows are gone before comming back and so i3 would likely exit before everything is closed. Especially if there are programs that ask for confirmation before closing ("Do you want to save before closing?").

Or you can use i3-nagbar to ask whether i3 should close all windows or just exit:

bindsym Mod4+Mod1+q exec i3-nagbar -t warning -m 'Close all windows or exit?' -b 'Close all windows' 'i3-msg [class="^(!?.*i3bar).*$"] kill' -b 'Exit i3' 'i3-msg exit'

This provides two buttons, "Close all windows" and "Exit i3". The second one will exit i3, no further questions asked. The first one will run the aforementioned command with the small change class criteria explicitly excludes the i3-bar. That way you can see on which workspace there are still open windows and take appropriate action. As the i3-nagbar stays open until explicitly closed (or until i3 exits) you can also repeatedly press "Close all windows".

edit flag offensive delete link more

Comments

Thanks. I use your command like this but not working: bindsym $mod+Alt+q for_window [class=".*"] kill

Ali gravatar imageAli ( 2014-11-10 11:10:48 +0000 )edit

@Ali Use `Mod1` instead of `Alt`, then it should work.

Adaephon gravatar imageAdaephon ( 2014-11-10 12:28:44 +0000 )edit

ERROR: Your command: for_window [class=".*"] kill

Ali gravatar imageAli ( 2014-11-10 15:18:51 +0000 )edit

`for_window` is not a command but a configuration option. When binding to a shortcut you need only `[<criteria>] <command>`. `for_window` is used to automatically run a command when a matching window appears. In this case you would automatically close every window immediatelly.

Adaephon gravatar imageAdaephon ( 2014-11-11 05:47:00 +0000 )edit

Thank you. Solved.

Ali gravatar imageAli ( 2014-11-11 20:33:16 +0000 )edit

Question Tools

Stats

Asked: 2014-11-09 12:28:30 +0000

Seen: 353 times

Last updated: Nov 12 '14