Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Do you know how to do it? I know how to do it from my keyboard (Alt+F4), I know how to do it with my mouse (click that X), and I also know that kill X should kill the process with the id X (and killall Y should kill the process named Y). But I want to know how to kill the active window from terminal.

Therefore, from what I stated above, a valid answer would also be to get the id of the active window.

Right now I'm implementing this function from xte (simulating Alt+F4), but I'd like to know if there's a way that doesn't imply installing another app. Thank you all.

EDIT. Here is the full script. First you enable 'show mouse when Ctrl is pressed', then you add this script to Commands in CompizConfig and binding to top-right corner. When you touch the top-right corner, a small notification around the mouse is shown. If you do nothing, the active window will close after 1 second. However, if you touch the corner again within the second, the active window will not be closed.

xte 'key Control_R'; if [ -f ~/.fcont ]; then rm -f -r ~/.fcont; else touch ~/.fcont; sleep 1;  if [ -f ~/.fcont ]; then xkill -id `xprop -root _NET_ACTIVE_WINDOW | cut -d\# -f2`; rm -f -r ~/.fcont; fi fi

Note that I still use the xte app named before since this question I made some time ago was never answered.

share|improve this question
add comment

2 Answers 2

up vote 4 down vote accepted

And if you want to get really hairy and avoid applications that aren't installed by default:

xkill -id `xprop -root _NET_ACTIVE_WINDOW | cut -d\# -f2`

Again, this seems to work fairly well.

NOTE: In the case of some applications (see comments) this may mean that all windows for an application are closed. gnome-terminal is one such application but terminator and xterm are not affected. I would suggest this is more a bug (maybe by design) with those applications rather than one with my command.

share|improve this answer
    
Perfect! actually I needed an app (of course), I didn't realize I actually wanted a pre-installed one. Thank you so much! –  Francisco Presencia Sep 4 '12 at 15:18
    
@FrankPresenciaFandos I think your edit is specific to Gnome-Terminal because I have tested this with Terminator and XTerm and it doesn't happen to them. –  Oli Sep 7 '12 at 17:16
    
Hmm. Well it also cascades for Nautilus (kills all listing windows plus the desktop). I don't know if there's a way to limit this effect to the Window. This seems to be something internal to xkill. Edit: You can confirm this by running xkill on its own - it nukes everything it can. –  Oli Sep 7 '12 at 17:22
add comment

I'd use xdotool:

xdotool windowkill `xdotool getactivewindow`

Seems to do the job quickly and quietly.

share|improve this answer
    
Thank you for your answer, I'll look into it, but from what I stated above, I'd like to know if there's a way that doesn't imply installing another app. –  Francisco Presencia Sep 4 '12 at 13:54
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.