PK!R+AFFklaxon/__init__.py__version__ = '0.1.0' from klaxon.main import klaxon, klaxonify, mainPK! klaxon/main.py#!/usr/bin/env python3 from functools import partial, wraps import subprocess as sp import argparse import shlex import sys def klaxon(message: str= '', title="Klaxon", subtitle="", sound=""): """ Wraps osascript. see https://apple.stackexchange.com/questions/57412/how-can-i-trigger-a-notification-center-notification-from-an-applescript-or-shel/115373#115373 """ command = f"""osascript -e 'display notification "{message}" with title "{title}" subtitle "{subtitle}" sound name "{sound}"'""" sp.run(shlex.split(command)) def klaxonify( func=None, title="Klaxon", message="", subtitle=None, sound="", output_as_message=False, ): """ Send a notification at the termination of a function. Args: func: the function to be decorated title: the notification title message: the notification message body subtitle: the notifiction subtitle sound: the notification sound output_as_message (bool): use the decorated function's output as the message body Returns: decorated function """ def decorator(function): @wraps(function) def inner(*args, **kwargs): result = function(*args, **kwargs) klaxon( subtitle=subtitle if subtitle is not None else function.__name__, message=message if not output_as_message else result, title=title, sound=sound, ) return result return inner if func is not None: return decorator(func) else: return decorator def main(): """Parse arguments from command line and pass to notify function.""" parser = argparse.ArgumentParser( prog="Klaxon", description="Send Mac OS notifications through osascript." ) parser.add_argument("--message", default="", help="The body of the notification") parser.add_argument("--title", default="Klaxon", help="The notification's title") parser.add_argument("--subtitle", default="", help="The notification's subtitle") parser.add_argument("--sound", help="The sound the notification makes") read_stdin = sys.argv.pop() if sys.argv[-1].strip() == "--" else None args = parser.parse_args() klaxon_ = partial( klaxon, title=args.title, subtitle=args.subtitle, sound=args.sound ) if read_stdin is None: klaxon_(args.message) else: with sys.stdin as fd: klaxon_(fd.read()) if __name__ == "__main__": main() PK!H_#&'klaxon-0.1.0.dist-info/entry_points.txtN+I/N.,()IϳPVy\\PK!HڽTUklaxon-0.1.0.dist-info/WHEEL A н#Z;/"d&F[xzw@Zpy3Fv]\fi4WZ^EgM_-]#0(q7PK!HJFNEklaxon-0.1.0.dist-info/METADATAJ1yy7V(,*JֵX!̚I靊Wok~Tg8pnH-d~ۙ1O-셀0( BKx VĚ;Ԍunw/GI[{LsĒ;x E %~zKn':j$vҼ^_-BW(mf1Ɛ/eme.}y;f+ nE+Yx] ;tUZgce*[z;E)P`J.M:>\^@*|zV~PK!R+AFFklaxon/__init__.pyPK! vklaxon/main.pyPK!H_#&' klaxon-0.1.0.dist-info/entry_points.txtPK!HڽTU klaxon-0.1.0.dist-info/WHEELPK!HJFNE klaxon-0.1.0.dist-info/METADATAPK!H`) klaxon-0.1.0.dist-info/RECORDPK