pythonmacososx-mavericks

Python post osx notification


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?


Solution

  • You should install terminal-notifier first with Ruby for example:

    $ [sudo] gem install terminal-notifier
    

    And then you can use this code:

    import os
    
    # The notifier function
    def notify(title, subtitle, message):
        t = '-title {!r}'.format(title)
        s = '-subtitle {!r}'.format(subtitle)
        m = '-message {!r}'.format(message)
        os.system('terminal-notifier {}'.format(' '.join([m, t, s])))
    
    # Calling the function
    notify(title    = 'A Real Notification',
           subtitle = 'with python',
           message  = 'Hello, this is me, notifying you!')
    

    And there you go:

    enter image description here