Sunday, April 28, 2024
 Popular · Latest · Hot · Upcoming
10
rated 0 times [  10] [ 0]  / answers: 1 / hits: 3290  / 3 Years ago, thu, november 4, 2021, 11:12:14

Is it possible to focus an opened app instance/window using a command?



I'd like to assign a keyboard shortcut as to quickly switch to a specific app.



I want shortcuts for:




  • chromium (now it opens a new window with blank tab)

  • terminator (now it opens a new window)



It works fine for these (running the default command, eg. thunderbird):




  • thunderbird

  • sublime text 2



I am using gnome-shell @ 12.04 (shouldn't matter)


More From » gnome

 Answers
3

The wmctrl package offers access and manipulation of application windows and would do what you want. Install this little package first:



sudo apt-get install wmctrl


Here is the man page for wmctrl:
http://manpages.ubuntu.com/manpages/precise/en/man1/wmctrl.1.html



When you look at the command line switches, you will see that -a will raise and focus a window. In order to know which window to focus, make sure you have a Chromium window open, and then run



wmctrl -l


This will give you a list of all open windows and their titles. Chromium will most likely always have "Chromium" in the end of it's window title, so you can use that.



With this information at hand, you can construct your command for the shortcut. Open the Keyboard preferences, go to Shortcuts, click on Custom Shortcuts, click the + sign and enter:



Name: Focus Chromium Shortcut
Command: wmctrl -a 'Chromium'


I am using Unity and just tried this with Google Chrome, it did the trick. It should work in Gnome-Shell as well.



Pretty cool idea :)



DrTebi


[#33455] Thursday, November 4, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
iething

Total Points: 49
Total Questions: 127
Total Answers: 112

Location: Luxembourg
Member since Tue, Jan 25, 2022
2 Years ago
;