Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import os
- import re
- """
- Go to window using dmenu.
- Requires wmctrl, xprop, and something I might have forgotten.
- Tested on Python 2.7.
- """
- """ Returns the window class, give a window ID """
- def get_window_class(id):
- xprop_wininfo = os.popen("xprop WM_CLASS -id " + id).read().split('\n')[:-1]
- return xprop_wininfo[0].split('"')[1]
- window_list = os.popen("wmctrl -l").read().split('\n')[:-1]
- # remove double spaces
- window_list = [x.replace(' ', ' ') for x in window_list]
- # a list of lists
- window_list = [x.split(' ',3) for x in window_list]
- # dict key: window name, value: window ID
- id_dict = { x[3]:x[0] for x in window_list}
- # get the classes of all windows
- class_dict = {x:get_window_class(x) for x in id_dict.values()}
- # combined dict: name+class:id
- win_dict = {}
- for win_name in id_dict.keys():
- id = id_dict[win_name]
- new_name = win_name + " (" + get_window_class(id) + ")"
- new_name = re.sub(r'[\x80-\xff]', '', new_name).lower()
- win_dict[new_name] = id
- # input for dmenu, newline separated
- dmenu_in = '"' + '\n'.join(win_dict.keys()) + '"'
- selection = os.popen("echo " + dmenu_in + " | dmenu").read()
- win_id = win_dict[selection]
- os.popen('wmctrl -i -a ' + win_id)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement