macOS / OS X notification using python

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):
              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