I am trying to connect to the Mountain Lion notification center via python. I've installed pyobjc and am following the instructions here and here. Also see: Working with Mountain Lion's Notification Center using PyObjC
Here's my code:
import Foundation, objc
import AppKit
import sysNSUserNotification = objc.lookUpClass('NSUserNotification')
NSUserNotificationCenter = objc.lookUpClass('NSUserNotificationCenter')def notify(title, subtitle, info_text, delay=0, sound=False, userInfo={}):""" Python method to show a desktop notification on Mountain Lion. Where:title: Title of notificationsubtitle: Subtitle of notificationinfo_text: Informative text of notificationdelay: Delay (in seconds) before showing the notificationsound: Play the default notification sounduserInfo: a dictionary that can be used to handle clicks in yourapp's applicationDidFinishLaunching:aNotification method"""notification = NSUserNotification.alloc().init()notification.setTitle_(title)notification.setSubtitle_(subtitle)notification.setInformativeText_(info_text)notification.setUserInfo_(userInfo)if sound:notification.setSoundName_("NSUserNotificationDefaultSoundName")notification.setDeliveryDate_(Foundation.NSDate.dateWithTimeInterval_sinceDate_(delay, Foundation.NSDate.date()))NSUserNotificationCenter.defaultUserNotificationCenter().scheduleNotification_(notification)
When I call the notify function with arguments I get an attribute error:
AttributeError: 'NoneType' object has no attribute 'scheduleNotification_'
I don't understand why NSUserNotificationCenter.defaultUserNotificationCenter()
is returning a NoneType object. I've not been able to query anything on this matter on the internet or SO.