#!/usr/bin/python import json import subprocess CONFIG = [ {'make': 'Samsung Electric Company', 'model': 'LS27A800U', 'position': 'left', 'workspace': 1}, {'make': 'Seanix Technology Inc', 'model': 'NX-EDG27X', 'position': 'center', 'workspace': 2}, {'make': 'BOE', 'model': '0x0BCA', 'position': 'right', 'workspace': 3}, ] p = subprocess.run( ['hyprctl', 'monitors', '-j'], capture_output=True, check=True, encoding='utf-8' ) monitors = json.loads(p.stdout) # print('monitors:', monitors) monitor_ids = {} for mon in monitors: for conf in CONFIG: if conf['make'] == mon['make'] and conf['model'] == mon['model']: monitor_ids[ conf['position'] ] = mon['id'] if len(monitor_ids) == len(CONFIG): print('config matched, assigning:') dispatches = [] for conf in CONFIG: workspace = conf['workspace'] monitor_id = monitor_ids[ conf['position'] ] # move workspace to desired monitor dispatches.append(f"dispatch moveworkspacetomonitor {workspace} {monitor_id}") # focus the workspace so that it's visible after moving dispatches.append(f"workspace {workspace}") cmd = ['hyprctl', '--batch', ' ; '.join(dispatches)] print('\n'.join(cmd)) subprocess.run(cmd, check=True) else: print('config not matched')