Created
December 19, 2013 15:19
-
-
Save erochest/8040797 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
"""Run a command and generate an alert when it's done.""" | |
import argparse | |
import subprocess | |
def alert(command, message=None): | |
message = message if message is not None else ' '.join(command) | |
retvalue = subprocess.call(command, shell=True) | |
message += "\nReturn code = {0}".format(retvalue) | |
subprocess.call(['terminal-notifier', '-message', message, '-title', 'alert']) | |
def parse_args(argv=None): | |
parser = argparse.ArgumentParser(description=__doc__) | |
parser.add_argument('-m', '--message', metavar='MESSAGE', | |
help='The alert message. Defaults to the command.') | |
parser.add_argument('command', metavar='SHELL_COMMAND', nargs='*', | |
help='The shell command to execute.') | |
args = parser.parse_args() | |
return args | |
def main(): | |
args = parse_args() | |
alert(args.command, args.message) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment