Python post osx notification

后端 未结 7 1167
没有蜡笔的小新
没有蜡笔的小新 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:23

    Try ntfy if you also want the script to be able to communicate with you over other devices.

    Installation

    [sudo] pip install ntfy 
    

    where pip refers to the Package Installer of the target Python version

    For Python3 installation:

    [sudo] pip3 install ntfy    
    

    Usage

    I use this simple function for notifications regarding command executions and download completions:

    def notification(title, message):
        """Notifies the logged in user about the download completion."""
    
        import os
        cmd = 'ntfy -t {0} send {1}'.format(title, message)
        os.system(cmd)
    
    notification("Download Complete", "Mr.RobotS01E05.mkv saved at /path")
    

    Advantages of ntfy

    1. This tool is quite handy as it logs all the notifications directly to the Notification Center rather than referring to other third-party application.

    2. Multiple Backend supports: This tool can connect to you over any device through services such as PushBullet, SimplePush, Slack, Telegram etc. Check the entire list of supported backend services here.

提交回复
热议问题