Python post osx notification

后端 未结 7 1169
没有蜡笔的小新
没有蜡笔的小新 2020-12-04 07:08

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 progra

7条回答
  •  不思量自难忘°
    2020-12-04 07:31

    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.

提交回复
热议问题