Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I create a script that automatically switches windows? I'm trying to do the same thing Alt+Tab does.

share|improve this question
up vote 10 down vote accepted

Sounds like you're looking for wmctrl - see here for more examples.

Edit: Your window manager/desktop environment has to be standards compliant (EWMH). And here are more examples.

share|improve this answer
Nice! I'll read a bit more about that. Thx. – GarouDan Oct 18 '11 at 13:48

In cases where sr_'s solution does not work, you can also try xautomation. One of the tools included in that package is xte (see manpage) - it simulates keystrokes, mouse movement and more. Here's how you can use it to simulate Alt+Tab:

xte "keydown Alt_L" "key Tab" "keyup Alt_L"
share|improve this answer
Thx a lot @rozcietrzewiacz. wmctrl worked fine. But looks like xautomation can't manipulate windows...can it? manpage In your link xautomation I didn't find no documenation... =/ – GarouDan Oct 18 '11 at 14:44
It can manipulate virtually anything that you can, when you see the screen - just use one of the shipped programs. See my updated answer about Alt+Tab. – rozcietrzewiacz Oct 18 '11 at 16:40
Thx so much @rozcietrzewiacz, really very powerfull this. I was needing a way to keep Shift pressed and this works perfectly! Thx. – GarouDan Oct 18 '11 at 20:00
is possible simulate F5 key by xte? Didn't find anything in xte or google yet. This is another question that I did. – GarouDan Oct 31 '11 at 11:54
@GarouDan Didn't you try? xte "key F5" works perfectly for me. – rozcietrzewiacz Oct 31 '11 at 12:04

Your Answer


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.