#!/usr/bin/python3

import pyatspi

def listener(e):
    try:
        if e.source.getRole() != pyatspi.ROLE_TEXT:
            return
    except:
        return

    words = e.any_data.split()
    words[4:-4] = "-"
    print("%i chars inserted by %s into %s (%s)" % \
          (len(e.any_data), e.host_application, e.source, " ".join(words)))

pyatspi.Registry.registerEventListener(listener, "object:text-changed:insert")
pyatspi.Registry.start()
