Skip to content

Instantly share code, notes, and snippets.

@jamesdh
Forked from lukaszb/notify.py
Created May 31, 2016 19:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesdh/48f15b34552810b34924ba10a0376634 to your computer and use it in GitHub Desktop.
Save jamesdh/48f15b34552810b34924ba10a0376634 to your computer and use it in GitHub Desktop.
Simple Python script to send notification to the OSX Notifications Center (requires OS X 10.8+). Tested with pyobjc 2.5.1
#!/usr/bin/env python
from Foundation import NSUserNotification
from Foundation import NSUserNotificationCenter
from Foundation import NSUserNotificationDefaultSoundName
from optparse import OptionParser
def main():
parser = OptionParser(usage='%prog -t TITLE -m MESSAGE')
parser.add_option('-t', '--title', action='store', default='A title')
parser.add_option('-m', '--message', action='store', default='...')
parser.add_option('--no-sound', action='store_false', default=True,
dest='sound')
options, args = parser.parse_args()
notification = NSUserNotification.alloc().init()
notification.setTitle_(options.title)
notification.setInformativeText_(options.message)
if options.sound:
notification.setSoundName_(NSUserNotificationDefaultSoundName)
center = NSUserNotificationCenter.defaultUserNotificationCenter()
center.deliverNotification_(notification)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment