Skip to content

Instantly share code, notes, and snippets.

@mseiwald
Created October 10, 2012 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mseiwald/3865875 to your computer and use it in GitHub Desktop.
Save mseiwald/3865875 to your computer and use it in GitHub Desktop.
#!/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