Class: Autometal::Growl

Inherits:
Object
  • Object
show all
Defined in:
lib/growl.rb

Overview

Creates a Growl notification with a custom title and body. Depends on Bob Harris’ growl Shell script http://hints.macworld.com/dlfiles/growl_sh.txt You will need to download, install, make executable and include the script path in your path.

Refer to http://hints.macworld.com/dlfiles/growl_sh.txt for installation details

Available options:

:sticky: Make a sticky notification. Default is false
:title: Notification title. Defaults to 'Script Notification'

Example

notification = Autometal::Growl.new(msg, :title => "Welcome to Sky Valley")
notification.transmit!

Constant Summary collapse

VERSION =
"1.0.1"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body, opts = {}) ⇒ Growl

Returns a new instance of Growl.

Raises:

  • (ArgumentError)


32
33
34
35
36
37
# File 'lib/growl.rb', line 32

def initialize body, opts = {}
  raise ArgumentError.new("Please provide a notification body") if [nil, false, ""].include?(body)
  @title  = opts.delete(:title) || "Script notification"
  @body   = body
  @sticky = opts[:sticky] == nil ? true : opts.delete(:sticky)
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



26
27
28
# File 'lib/growl.rb', line 26

def body
  @body
end

#stickyObject

Returns the value of attribute sticky.



26
27
28
# File 'lib/growl.rb', line 26

def sticky
  @sticky
end

#titleObject

Returns the value of attribute title.



26
27
28
# File 'lib/growl.rb', line 26

def title
  @title
end

Instance Method Details

#cmd_pathObject



28
29
30
# File 'lib/growl.rb', line 28

def cmd_path
  File.join("/","usr","local","bin","growl")
end

#transmit!Object



39
40
41
42
# File 'lib/growl.rb', line 39

def transmit!
  response = execute_shell_command
  raise Autometal::GrowlException.new unless response
end