#!/usr/bin/env python3 import json import os import struct import subprocess import sys def send(msg): data = json.dumps(msg).encode('utf-8') sys.stdout.buffer.write(struct.pack('I', len(data))) sys.stdout.buffer.write(data) sys.stdout.buffer.flush() def read(): raw = sys.stdin.buffer.read(4) if len(raw) == 0: return None length = struct.unpack('I', raw)[0] return json.loads(sys.stdin.buffer.read(length).decode('utf-8')) def get_accent(): try: helper = os.path.join(os.path.dirname(__file__), '..', 'getaccent') color = subprocess.check_output([helper], stderr=subprocess.DEVNULL).decode().strip() if color: return color except Exception: pass return '#000000' while True: msg = read() if msg is None: break if msg.get('query') == 'color': send({'color': get_accent()})