Created
August 26, 2020 06:41
-
-
Save yehgdotnet/d1e1a36fd75c3d7f070ed481eb211e4b to your computer and use it in GitHub Desktop.
Python 2 Mac OS Notification
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
#!/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