Skip to content

Instantly share code, notes, and snippets.

@copiousfreetime
Created January 28, 2009 17:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save copiousfreetime/54095 to your computer and use it in GitHub Desktop.
Save copiousfreetime/54095 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
##
# alert_me
#
# A simple delay timer to send a growl notification at specific time with a
# message. Useful for when you need to check on something later
#
# echo "Go look at system 42" | alert_me in 2 hours
#
##
require 'rubygems'
require 'ruby-growl'
require 'chronic'
require 'daemons'
default_alert = Chronic.parse( "in 10 secods" )
alert_time = Chronic.parse( ARGV.join(" ") ) || default_alert
if alert_time < Time.now then
STDERR.puts "Unable to do an alert in the past"
exit 1
end
delay = alert_time - Time.now
message = STDIN.read
if message.size == 0 then
STDERR.puts "You need a message"
exit 1
end
app_name = File.basename( __FILE__ )
hostname = "localhost"
password = nil
sticky = true
priority = 1
notify_type = "Alert Me Notification"
title = "Alert Me Notification"
Daemons.daemonize
$0 = "alert at #{alert_time.strftime("%Y-%m-%d %H:%M:%S")}"
sleep delay
g = Growl.new( hostname, app_name, [notify_type], [notify_type], password )
g.notify( notify_type, title, message, priority, sticky )
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment