macOS Python Notification

While looking for a solution to have my computer notify me when something
happens, I started to search for a solution using python.
It is possible to use python without any other third party libraries to post a
notification with your own *title*, *text* and *sound*.
A great solution was posted on stackexchange Python post osx notification.

import os

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

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

With valid sounds from
~/Library/Sounds
/System/Library/Sounds

You can read a little more about it over at the apple developer website Display Notification
Also this answer on Stackexchange has a great explanantion


112 Words

2019-05-26 13:54 +0200