Skip to content

Instantly share code, notes, and snippets.

@ticklemynausea
Last active May 11, 2020 14:04
Show Gist options
  • Save ticklemynausea/4792ed1ee1484cef1de09d51c5e8a53d to your computer and use it in GitHub Desktop.
Save ticklemynausea/4792ed1ee1484cef1de09d51c5e8a53d to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import sys
import pync
def write_stdout(s):
# only eventlistener protocol messages may be sent to stdout
sys.stdout.write(s)
sys.stdout.flush()
def write_stderr(s):
sys.stderr.write(s)
sys.stderr.flush()
def main():
while 1:
# transition from ACKNOWLEDGED to READY
write_stdout('READY\n')
# read header line and print it to stderr
line = sys.stdin.readline()
write_stderr(line)
# read event payload and print it to stderr
headers = dict([ x.split(':') for x in line.split() ])
data = sys.stdin.read(int(headers['len']))
write_stderr(data)
h = dict(map(lambda s: tuple(s.split(":", 1)), data.split(" ")) | headers.items())
title = "Fractal ID"
message = "%s is %s" % (h.get("processname"), h.get("eventname").replace("PROCESS_STATE_", "").lower())
if h.get("pid"):
message += " with PID %s" % (h.get("pid"))
if h.get("processname") != "notifier":
pync.notify(message, appIcon="/Users/mario/.bin/fractal.png", title=title)
# transition from READY to ACKNOWLEDGED
write_stdout('RESULT 2\nOK')
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment