How do I switch to already running program using terminal?
For examaple:
firefox
opens new firefox window.
Is there a command that will focus the already opened firefox window?
command line
How do I switch to already running program using terminal?
For examaple:
firefox
opens new firefox window.
Is there a command that will focus the already opened firefox window?
Best Answer
As a one- liner
Assuming you have wmctrl installed (run
sudo apt-get install wmctrl
if not):The command:
Would raise the last opened
gedit
window. Replace it by any other application.Explanation
gets the pid of gedit
lists all windows and the pid they belong to
splits off the window- id (the first string in the line)
therefore finds the window-id of the last created window of
gedit
(the output ofwmctrl -lp
lists the windows in a chronological order of creation, if the application has multiple windows,tail -1
returns the last one).subsequently raises the window by its
window-id
In a small script
...to be run with the application as argument:
switchto.sh
Run it as (e.g.)
Alternatives?
Theoretically the command:
should do (kind of) the same; it should raise the first found window of
gedit
in this case.It seems less robust however. On my system (Unity) it did nothing at all.