#!/usr/bin/env python3
import sys
import json
import subprocess
def find_focused_parent(node):
if 'nodes' in node:
for child in node['nodes']:
if child.get('focused'):
return node
parent = find_focused_parent(child)
if parent:
return parent
return None
if len(sys.argv) == 2:
target_index = int(sys.argv[1]) - 1 # Convert 1-based input to 0-based index
# Grab the current window tree from i3
tree_data = subprocess.check_output(['i3-msg', '-t', 'get_tree'])
tree = json.loads(tree_data)
parent = find_focused_parent(tree)
# If a parent is found and the requested tab index exists, focus it
if parent and 0 <= target_index < len(parent['nodes']):
target_id = parent['nodes'][target_index]['id']
subprocess.run(['i3-msg', f'[con_id={target_id}] focus'], stdout=subprocess.DEVNULL)
make a key binding for this script like this
bindsym $mod+Ctrl+1 exec --no-startup-id ~/.config/i3/i3-file-name.py 1
bindsym $mod+Ctrl+1 exec --no-startup-id ~/.config/i3/i3-file-name.py 2
2 second prompt
anon please fuck off its not a tech support board, although it has its generals for that, you'd already have an answer if you posted that question on reddit