Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Persistent Growl notifications for long tasks' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Persistent Growl notifications for long tasks
Authored by: Seth Milliken on Oct 14, '10 04:21:49PM
Here's a python script I use to do this more generally. With this script saved as executable in ~/bin/grun and ~/bin in my $PATH, I can precede any command with "grun" to have it report completion via growlnotify.

#!/usr/bin/python
# 
# grun
#
# Run a commandline that posts a growl notification when it completes.
# Each command gets its own individual sticky notification that is updated on completion.
#
# TODO: parameterize growlnotify location
# TODO: support && compound commands, e.g. grun.py (echo "Initial output." && sleep 5 && echo "Final output.")
#
from sys import argv
import os, subprocess, string

original_command = " ".join(argv[1:])

def postnotification(identifier, title, message):
    os.system("growlnotify --identifier " + str(identifier) + " --sticky -a 'Terminal.app' -t '" + title + "' -m \"" + message + "\"")

p = subprocess.Popen(argv[1:])
postnotification(p.pid, "running shell command", original_command)
status = os.waitpid(p.pid, 0)[1]
postnotification(p.pid, "shell command completed", original_command + " (" + str(status) + ")")


[ Reply to This | # ]