After I navigate out to a webpage or editor, is there any way to bring all the open terminals back to the front in their original positions? It is a bit of a pain clicking the terminal icon and then bringing each one back individually.
Thanks!
Example:
- Pre-shortcut:
- Post-shortcut:
4 Answers
You can press Alt+Tab to switch forward between windows and Alt+Shift+Tab to switch back between windows. This shortcut is made to work in almost all graphical operating systems. Yow can also use Super+W and arrow keys for the same purpose.
After you bring one terminal window in the front, press Alt+~ to bring all other terminal windows in the front one by one:
To automatically bring all open terminals in the front (not one by one as I described before) you will need to add a keyboard shortcut for the following script (script taken from Adobe's answer and improved considering that version of script hasn't worked for me):
#!/bin/bash
if [ $# -ne 1 ];then echo -e "Usage: `basename $0` PROGRAM_NAME\n For example:\n\t '`basename $0` gnome-terminal' for Terminal\n\t '`basename $0` firefox' for Firefox\n\t '`basename $0` chromium-browser' for Chromium\n\t..." exit 1
fi
pids=" $(pidof $@) "
if [ "$pids" = " " ]; then # the string " " contain two spaces echo "There is no program named '$@' opened at the moment." exit 1
fi
wmctrl -lp | while read identity desktop_number PID window_title; do if [ "${pids/ $PID }" != "$pids" ]; then wmctrl -ia $identity fi
doneDon't forget to make the script executable:
chmod +x /path/to/script/script_nameAfter you test the script in terminal, you must to see:
- How can I change what keys on my keyboard do? (How can I create custom keyboard commands/shortcuts?)
Here's a small bash script which brings all the windows whose title matches ARG to the front:
bring-all-windows.bash ARGThe script:
#!/bin/bash
Program=$@
wmctrl -l | while read Window; do if [[ "$Window" == *"$Program"* ]]; then echo "DEBUG: I bring $Window" code=`echo "$Window" | cut -f 1 -d " "` wmctrl -i -a $code fi
doneYou can bind
bring-all-windows.bash Terminalto a hotkey (don't forget to put the script in a login shell PATH, or write a full path to it).
The script requires wmctrl to be installed.
Edit:
To run something from the terminal, navigate to the dir where you put the script, then
chmod +x bring-all-windows.bash
./bring-all-windows.bash TerminalWhen you're sure it works from the terminal, try to bind it to a hotkey, giving the full path. When you're sure it works with a hotkey and the full path to the script, then try adding it's dir to the login shell PATH, and see if it works that way.
8Another way is using xdotool. You should install it first so sudo apt-get install xdotool is mandatory.
xdotool search --class "terminal" windowactivate %@
xdotool search --name "braiam@bt" windowactivate %@The first look for any binary called *terminal*, the second looks for any window that has as title *braiam@bt*. Then if you put that into a bash script:
#!/bin/bash
set -e
program=$@
xdotool search --class '$program' windowactivate %@
xdotool search --name '$program' windowactivate %@You can know more about this in the xdotool manual.
Graphically in my Ubuntu desktop, I have my icons arranged vertically on the left-hand side margin of my desktop. If you left click on the terminal icon, you will see all the terminal windows. Then you can pick whichever one to work in. If you right click on the terminal icon, you will see a list of menus with a "New terminal" on top, and all your open terminal in the lower portion of the list. You can select whichever to be your active terminal.
This same method should work for any other application such as your browser.