How can I create a script that automatically switches windows? I'm trying to do the same thing Alt+Tab does.
3 Answers
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.
- Nice! I'll read a bit more about that. Thx.GarouDan– GarouDan2011-10-18 13:48:07 +00:00Commented Oct 18, 2011 at 13:48
- 1Thanks for the link to wmctrl. Unfortunately it looks like your first link is broken. Here's man wmctrl, which might help others.Alex– Alex2017-02-26 18:17:05 +00:00Commented Feb 26, 2017 at 18:17
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" - 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– GarouDan2011-10-18 14:44:48 +00:00Commented Oct 18, 2011 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– rozcietrzewiacz2011-10-18 16:40:27 +00:00Commented Oct 18, 2011 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– GarouDan2011-10-18 20:00:19 +00:00Commented Oct 18, 2011 at 20:00
-
- 1@GarouDan Didn't you try?
xte "key F5"works perfectly for me.rozcietrzewiacz– rozcietrzewiacz2011-10-31 12:04:31 +00:00Commented Oct 31, 2011 at 12:04
The answer from sr_ mentioned wmctrl, which works for me.
I installed it on Ubuntu 16.04 with sudo apt-get install wmctrl. I was able to switch window with wmctrl -a emacs24.
wcmtrl -a $WIN seems to search for windows with names that contain the string $WIN. The search is case-insensitive.
Here is man wmctrl for reference.