I am having some trouble understanding how to get an NSUserNotification's action button to do something using Python. I think I understand that "userNotificationCenter_didActivateNotification_" is called when a user clicks the button?
But I can't work out how to receive the notification and use it to call a custom method - i am using a call to os.system("say") just as a test
I have tried setting the class's delegate to self but it doesn't seem to make a difference.
Any ideas would be appreciated!
Cheers
Adam
This is what I have as a class that I call from another script when something is completed:
#!/usr/bin/env python
import Foundation, objc
import AppKit
import sys
import os
import logging
from Foundation import NSUserNotification
from Foundation import NSUserNotificationCenter
from optparse import OptionParser
class Notification_osx:
def __init__(self, item,proyecto):
self.item = item
notification = NSUserNotification.alloc().init()
notification.setTitle_("Notification: " + proyecto)
notification.setSubtitle_("Un archivo nuevo esta disponible:")
notification.setInformativeText_(item)
notification.setHasActionButton_(True);
notification.setActionButtonTitle_("Donde?")
home = os.path.expanduser("~")
LOG_FILENAME = os.path.join(home,'Desktop','sync.log')
logging.basicConfig(filename=LOG_FILENAME,level=logging.DEBUG)
logging.debug(notification.description)
# notification.setUserInfo_({"action":"open_url", "value":item})
# if options.sound:
# notification.setSoundName_("NSUserNotificationDefaultSoundName")
center = NSUserNotificationCenter.defaultUserNotificationCenter()
center.setDelegate_(self)
center.deliverNotification_(notification)
# center.didActivateNotification_(notification)
def userNotificationCenter_shouldPresentNotification_(self, center, notification):
os.system("say hola")
return True
def userNotificationCenter_didDeliverNotification_(self, center, notification):
os.system("say hola")
def userNotificationCenter_didActivateNotification_(self, center, notification):
# userInfo = notification.userInfo()
os.system("say hola")