Skip to content

Instantly share code, notes, and snippets.

@knowsuchagency knowsuchagency/notify
Last active Jul 5, 2018

Embed
What would you like to do?
A notification script for mac os
#!/usr/bin/env python3
import subprocess as sp
import argparse
import shlex
def notify(message: str, title='', 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 main():
"""Parse arguments from command line and pass to notify function."""
parser = argparse.ArgumentParser()
parser.add_argument('message', help="The body of the notification")
parser.add_argument('--title', help="The notification's title")
parser.add_argument('--subtitle', help="The notification's subtitle")
parser.add_argument('--sound', help="The sound the notification makes")
args = parser.parse_args()
notify(args.message, title=args.title, subtitle=args.subtitle, sound=args.sound)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.