Advertisement
darkenvy

pyNotificationCenter.py

Jan 22nd, 2015
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.27 KB | None | 0 0
  1. # Python integration with Mountain Lion's notification center
  2.  
  3. import Foundation, objc
  4.  
  5. NSUserNotification = objc.lookUpClass('NSUserNotification')
  6. NSUserNotificationCenter = objc.lookUpClass('NSUserNotificationCenter')
  7.  
  8. def notify(title, subtitle, info_text, delay=0, sound=False, userInfo={}):
  9.   """ Python method to show a desktop notification on Mountain Lion. Where:
  10.        title: Title of notification
  11.        subtitle: Subtitle of notification
  12.        info_text: Informative text of notification
  13.        delay: Delay (in seconds) before showing the notification
  14.        sound: Play the default notification sound
  15.        userInfo: a dictionary that can be used to handle clicks in your
  16.                  app's applicationDidFinishLaunching:aNotification method
  17.  """
  18.   notification = NSUserNotification.alloc().init()
  19.   notification.setTitle_(title)
  20.   notification.setSubtitle_(subtitle)
  21.   notification.setInformativeText_(info_text)
  22.   notification.setUserInfo_(userInfo)
  23.   if sound:
  24.     notification.setSoundName_("NSUserNotificationDefaultSoundName")
  25.   notification.setDeliveryDate_(Foundation.NSDate.dateWithTimeInterval_sinceDate_(delay, Foundation.NSDate.date()))
  26.   NSUserNotificationCenter.defaultUserNotificationCenter().scheduleNotification_(notification)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement