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 Nov 9 '14

Ali gravatar image

updated Nov 12 '14

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?

1 answer

Sort by » oldest newest most voted
1

answered Nov 10 '14

Adaephon gravatar image

updated Nov 11 '14

[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".

Comments

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

Ali gravatar imageAli (Nov 10 '14)edit

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

Adaephon gravatar imageAdaephon (Nov 10 '14)edit

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

Ali gravatar imageAli (Nov 10 '14)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 (Nov 11 '14)edit

Thank you. Solved.

Ali gravatar imageAli (Nov 11 '14)edit

Question Tools

Stats

Asked: Nov 9 '14

Seen: 353 times

Last updated: Nov 12 '14