3

I want to send a notification to my mac's notification center with python code.

I'm using python3 on macOS Mojave version 10.14.6 with Atom as my editor. I've tried using different methods, like notify2 (which didn't work, there was a problem with dbus which I couldn't solve) and notify-send (which replied RuntimeError: Unsupported operating system: darwin). So, now, I'm trying to use the OS module. This is my code so far:

import os
mstr='Hello'
os.system('notify-send '+mstr)

When I run it from terminal, it outputs sh: notify-send: command not found. If I run it from IDLE, Python's default editor, nothing happens.

What do I do? Are there other alternatives to send notifications?

bucketfish
  • 51
  • 1
  • 4
  • Possible duplicate of [Python post osx notification](https://stackoverflow.com/questions/17651017/python-post-osx-notification) – maxrodrigo Sep 30 '19 at 04:05

2 Answers2

2

Sorry! I found a fix for this after going around the web. Here it is!

import os
mstr='Hello'
os.system("osascript -e 'display notification \"hello world!\"\'")```
bucketfish
  • 51
  • 1
  • 4
0

One of the alternatives is the macos-notifcations. Check it out :)

Disclaimer: I am the creator of macos-notifications.

A short example for you of the functionality it has:

Small example 1

Jorrick Sleijster
  • 935
  • 1
  • 9
  • 22