Skip to content

Instantly share code, notes, and snippets.

@rgs1
Created October 13, 2023 19:11
Show Gist options
  • Save rgs1/ad15936ce8b47969b7de643b26959ade to your computer and use it in GitHub Desktop.
Save rgs1/ad15936ce8b47969b7de643b26959ade to your computer and use it in GitHub Desktop.
from pync import Notifier
from Foundation import NSUserNotificationCenter, NSObject, NSRunLoop, NSDate
class NotificationDelegate(NSObject):
def userNotificationCenter_didDeliverNotification_(self, center, notification):
title = notification.title()
subtitle = notification.subtitle()
message = notification.informativeText()
print(f"Received notification:\nTitle: {title}\nSubtitle: {subtitle}\nMessage: {message}\n")
def main():
delegate = NotificationDelegate.alloc().init()
NSUserNotificationCenter.defaultUserNotificationCenter().setDelegate_(delegate)
# Run the main event loop to listen for notifications
run_loop = NSRunLoop.currentRunLoop()
while True:
run_loop.runUntilDate_(NSDate.dateWithTimeIntervalSinceNow_(1))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment