Created
October 10, 2012 14:11
-
-
Save mseiwald/3865875 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python2 | |
import re | |
import subprocess | |
import json | |
def get_windows(node): | |
windows = [] | |
for n in node['nodes']: | |
if n['nodes']: | |
windows += get_windows(n) | |
else: | |
windows.append(n['name']) | |
return windows | |
def main(): | |
stdout = subprocess.check_output('i3-msg -t get_tree', shell=True) | |
js = json.loads(stdout) | |
windows = [] | |
windows += get_windows(js['nodes'][1]['nodes'][1]) | |
window_list = '\n'.join(windows).encode('utf-8') | |
p = subprocess.Popen('dmenu -i', stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True) | |
window = p.communicate(input=window_list)[0] | |
window = re.escape(window.strip()) | |
cmdline = 'i3-msg "[title=\\"%s\\"] focus"' % window | |
subprocess.call(cmdline, shell=True, stdout=subprocess.PIPE) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment