Skip to content

Instantly share code, notes, and snippets.

@dpyro
Created March 15, 2017 20:02
Show Gist options
  • Save dpyro/2e3eec476f4828c6fe95a793c43f0a9f to your computer and use it in GitHub Desktop.
Save dpyro/2e3eec476f4828c6fe95a793c43f0a9f to your computer and use it in GitHub Desktop.
function to display notification on macOS
import os
import sys
def notify(text, title=None, subtitle=None, sound_name=None):
"""
Displays a notification on macOS systems using AppleScript.
"""
if sys.platform.startswith('darwin'):
cmd = "osascript -e 'display notification \"{}\"".format(text)
args = []
if title is not None: args.append('with title "{}"'.format(title))
if subtitle is not None: args.append('subtitle "{}"'.format(subtitle))
if sound_name is not None: args.append('sound name "{}"'.format(sound_name))
if len(args) > 0: cmd += " " + " ".join(args)
cmd += "'"
print(cmd)
os.system(cmd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment