Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I send a notification with python to mac notifications center?

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?

like image 691
bucketfish Avatar asked Oct 31 '25 02:10

bucketfish


2 Answers

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!\"\'")```
like image 100
bucketfish Avatar answered Nov 01 '25 16:11

bucketfish


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

like image 28
Jorrick Sleijster Avatar answered Nov 01 '25 17:11

Jorrick Sleijster



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!