Python post osx notification

kyle k picture kyle k · Jul 15, 2013 · Viewed 28.8k times · Source

Using python I am wanting to post a message to the OSX Notification Center. What library do I need to use? should i write a program in objective-c and then call that program from python?


update

How do I access the features of notification center for 10.9 such as the buttons and the text field?

Answer

Christopher Shroba picture Christopher Shroba · Dec 25, 2016

All the other answers here require third party libraries; this one doesn't require anything. It just uses an apple script to create the notification:

import os

def notify(title, text):
    os.system("""
              osascript -e 'display notification "{}" with title "{}"'
              """.format(text, title))

notify("Title", "Heres an alert")

Note that this example does not escape quotes, double quotes, or other special characters, so these characters will not work correctly in the text or title of the notification.