Skip to content

Instantly share code, notes, and snippets.

@gniemetz
Created September 24, 2017 15:39
Show Gist options
  • Save gniemetz/65c2e287024e3317afc91da34fb12f31 to your computer and use it in GitHub Desktop.
Save gniemetz/65c2e287024e3317afc91da34fb12f31 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import AppKit
import Foundation
def notify(title, subtitle, info_text, sound=False, appImage=None, contentImage=None, delay=0):
notification = Foundation.NSUserNotification.alloc().init()
notification.setTitle_(title)
notification.setSubtitle_(subtitle)
notification.setInformativeText_(info_text)
if appImage:
source_img = AppKit.NSImage.alloc().initByReferencingFile_(appImage)
notification.set_identityImage_(source_img)
if contentImage:
source_img = AppKit.NSImage.alloc().initByReferencingFile_(contentImage)
notification.setContentImage_(source_img)
if sound:
notification.setSoundName_("NSUserNotificationDefaultSoundName")
notification.setDeliveryDate_(Foundation.NSDate.dateWithTimeInterval_sinceDate_(delay, Foundation.NSDate.date()))
Foundation.NSUserNotificationCenter.defaultUserNotificationCenter().scheduleNotification_(notification)
notify("Macbrained.org", "Python for the Bash Scripter", "Notify!", True )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment