JokerQyou
5/3/2015 - 9:56 AM

A python lib for sending notification on OS X

A python lib for sending notification on OS X

# coding: utf-8
from Foundation import NSUserNotification
from Foundation import NSUserNotificationCenter
from Foundation import NSUserNotificationDefaultSoundName

def notify(message, title='Notification', sound=False):
    notification = NSUserNotification.alloc().init()
    notification.setTitle_(title)
    notification.setInformativeText_(message)
    if sound:
        notification.setSoundName_(NSUserNotificationDefaultSoundName)

    center = NSUserNotificationCenter.defaultUserNotificationCenter()
    center.deliverNotification_(notification)


if __name__ == '__main__':
    notify('This is a notification test', title='Test script', sound=True)