Any way to open windows from the windows bar using a shortcut
Any way to open windows from the windows bar using a shortcut? for example to open the first window on the left Ctrl+1, to open the second window on the left Ctrl+2.
Im using xfce4 at this moment, but if under xfce4 is not possible, is there any other desktop environment that permits this?
Since I have several windows open for the same application, I not searching for sortcuts related to the application but as I say below, to the window.
Solution 1:
With a little script and a small surgery on your system, it can be arranged exactly as you describe.
Ingredients
-
wmctrl
; it possibly needs to be installed. - The script below
-
xprop
, to get the window properties. This is already installed on your system. - Settings changes in xfce panel settings
- Additional keyboard shortcuts
How to set up
-
Install
wmctrl
:sudo apt-get install wmctrl
Create a directory
~/bin
(/home/<yourname>/bin
). Copy the script below into an empty file, save it aspanel_navigate
(no extension) in~/bin
and make it executable.-
Change panel settings:
Go to Settings Manager > "Panel" > "Items" (tab) > "Window Buttons" >- "Sorting order" > Choose: Timestamp
- "Window Grouping" > Choose: "Never"
- Make sure "Show windows from all workspaces or viewports" is unticked
- "Sorting order" > Choose: Timestamp
-
Add Keyboard shortcuts:
go to Settings Manager > "Keyboard" > "Application Shortcuts", choose "Add". Add the command:panel_navigate 1
Set it to the key combination Ctrl+1
-
Now you can choose:
- to repeat this procedure to add
panel_navigate 2
under Ctrl+2 and so on (until 9)
(save option) or (if you are not afraid to edit config files manually):
-
you can edit the file:
~/.config/xfce4/xfconf/xfce-perchanel-xml/xfce4-keyboard-shortcuts.xml
in which the keyboard shortcuts (in
xfce
) are stored. Open the file withmousepad
and look for a line like:<property name="<Primary>1" type="string" value="panel_navigate 1"/>
Copy the line, paste it on the next line (insert) and change both occurrences of 1 into 2, so you'll get:
<property name="<Primary>1" type="string" value="panel_navigate 1"/> <property name="<Primary>2" type="string" value="panel_navigate 2"/>
and so on..
Make sure the indent is exactly the same. Repeat the procedure until 9.
- to repeat this procedure to add
Log out and back in and it should work:
Ctrl+1
Ctrl+3
And so on...
The script
#!/usr/bin/env python3
import subprocess
import sys
def get_value(command):
return subprocess.check_output(["/bin/bash", "-c", command]).decode("utf-8").strip()
def run_command(command):
subprocess.Popen(["/bin/bash", "-c", command])
current_workspace = [l for l in get_value("wmctrl -d").splitlines() if l.split(" ")[2] == "*"][0][0]
wlist_ids = [item.split()[0:4] for item in get_value("wmctrl -l").splitlines()]
relevant = [item for item in wlist_ids if item[1] == current_workspace]
panel = []
for item in relevant:
data = get_value("xprop -id "+item[0])
if ("_TYPE_NORMAL" in data, "TYPE_DIALOG" in data).count(True) == 1:
panel.append(item)
try:
window = panel[int(sys.argv[1])-1][0]
run_command("wmctrl -ia "+window)
except IndexError:
pass
Explanation
The solution is an opportunistic one. It occurred to me that the windowlist, called by the command wmcrl -l
, is ordered by the age of the windows. By making the xfce panel do the same (settings), both orders are corresponding perfectly. What the script does is creating a window list, filtering out the "real", visible windows (with xprop
) and switch to a chosen window by the command panel_navigate
, with the number of the window (from the left to the right) as an agrument.
Issues
I noticed one exception: the IDLE (python interpreter) windows have pid 0 and their properties can not be "researched" by xprop
. The windows do not appear in the windowlist and are skipped by the script.
Note
Although the Key combination Ctrl+<number>
didn't raise any errors while testing, it might conflict with some applications. It might be safer to choose (e.g.)
Ctrl+Alt+1
Solution 2:
Not sure for the same application, but in Unity
you can switch applications with super+number
, as for example, super + 1
= first item on the launcher, super + 2
= the second item of the launcher, super + n
= the nth item of the launcher. This also helps to open any item placed on the launcher, like if nautilus is the first item of the launcher, super + 1
will open up nautilus file manager.