Created
November 5, 2012 21:53
-
-
Save baliw/4020619 to your computer and use it in GitHub Desktop.
Mountain Lion Notification Center via Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import objc | |
import AppKit | |
import sys | |
NSUserNotification = objc.lookUpClass('NSUserNotification') | |
NSUserNotificationCenter = objc.lookUpClass('NSUserNotificationCenter') | |
def notify(title, subtitle, info_text, delay=0, sound=False, userInfo={}): | |
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) | |
notify("Test message", "Subtitle", "This message should appear instantly, with a sound", sound=True) | |
sys.stdout.write("Notification sent...\n") | |
Getting following error on MAC OS 10.13 onwards: error: NSInvalidUnarchiveOperationException - Class 'OC_PythonDictionary' has a superclass that supports secure coding, but 'OC_PythonDictionary' overrides -initWithCoder: and does not override +supportsSecureCoding. The class must implement +supportsSecureCoding and return YES to verify that its implementation of -initWithCoder: is secure coding compliant.
Is it possible to set a callback? For example, when a button is pressed, open a URL
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am getting this error:
Should I install
pyobjc
?.