Skip to content

Instantly share code, notes, and snippets.

@squizzi
Last active August 27, 2018 14:19
Show Gist options
  • Save squizzi/f34d2d41d36ec8f9ab514336ec26864a to your computer and use it in GitHub Desktop.
Save squizzi/f34d2d41d36ec8f9ab514336ec26864a to your computer and use it in GitHub Desktop.
Send errors through notify-send, good for use with autokey scripts
#!/usr/bin/env python
import os
from subprocess import Popen
"""
Notify users via notify-send in gnome-shell, if sending an error use is_error=True
Edit service_title with the desired title notify-send will use when sending msg
"""
def notify_msg(msg, service_title="Your service here", is_error=False):
# Determine which level we should write to
# Critical gives us a red '!'
if not is_error:
urgency = 'normal'
else:
urgency = 'critical'
# Check to see if notify-send even exists first
if os.path.isfile('/usr/bin/notify-send'):
# Send an error message with notify-send
notify_send = [
"/usr/bin/notify-send",
"-u", "{}".format(urgency),
"{}".format(service_title),
"{}".format(msg)
]
Popen(notify_send)
else:
# We'll log via print for debug, but do nothing since
# notify-send doesn't exist
print 'WARNING: notify-send was not found, unable to send errormsg in gui'
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment