Skip to content

Instantly share code, notes, and snippets.

@samuelantonioli
Created February 8, 2021 14:25
Show Gist options
  • Save samuelantonioli/1c8d571f4103fb7109de5f9733bd286f to your computer and use it in GitHub Desktop.
Save samuelantonioli/1c8d571f4103fb7109de5f9733bd286f to your computer and use it in GitHub Desktop.
mac-notification.py
import os
def notify(title, msg = ''):
'''small osascript notification with proper quotes escaping. don't use this with user input!'''
clean_str = lambda x: x.replace('"', '\\"').replace('\'', '\'\\\'\'')
os.system('osascript -e \'display notification "{}" with title "{}"\''.format(
clean_str(msg),
clean_str(title)
))
notify('Test - "Tiffany\'s Donut Store"', '"Whatever, Bernard" - Tiffany')
# osascript -e 'display notification "hello world!" with title "This is the title"'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment