When working with Python on macOS, triggering native notifications can be useful for alerts, automation feedback, or status updates. Here are two approaches:
1. Using pync
(Preferred)
The pync
library is a simple wrapper for macOS's osascript
notification system. It's lightweight, clean, and easy to use:
```python
from pync import Notifier
Notifier.notify(
title='SUCCESS',
message=f'🟢🟢🟢 TEST with from pync import Notifier',
)
Pros:
✅ Simple and clean syntax
✅ Works asynchronously
✅ No extra shell calls
Cons:
❌ Requires installing pync (pip install pync)
⸻
- Using osascript (More Flexible)
If you don’t want to install an external package, you can directly invoke AppleScript via osascript:
import os
os.system(f'''
osascript -e 'display dialog "🟢🟢🟢 Added to NicAI campaign:\n{linkedin_handle}" with title "SUCCESS" buttons {{"OK"}} default button "OK"'
''')
OR
display alert
Pros:
✅ No extra dependencies
✅ Can create interactive dialogs
Cons:
❌ Uses shell execution (slower, more overhead)
❌ Less clean than pync
⸻
Which One Should You Use?
• If you just need a simple notification, use pync.
• If you need a custom dialog with buttons, use osascript.
Both work, pick what fits your use case.