Module: Kernel

Defined in:
lib/system_control/growl.rb

Instance Method Summary collapse

Instance Method Details

#g(*args) ⇒ Object

Sends a Growl Notification. This method needs three arguments(two arguments are optional).

Examples:

g "Description"
g "Description", {:sticky => true}
g "Notification title", "Description"
g "Notification title", "Description", {:sticky => true}

Parameters:

  • title (String)

    The title that should be used in the Growl notification. This is optional argument. Defaults to "MacRuby".

  • description (String)

    The body of the Grow notification.

  • options (Hash)

    Specifies a few optional options.<br>

    • :sticky - indicates if the Grow notification should "stick" to the screen. Defaults to false.<br>

    • :priority - sets the priority level of the Growl notification. Defaults to 0.

Raises:

  • (ArgumentError)


91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/system_control/growl.rb', line 91

def g(*args)
  size = args.size
  raise ArgumentError, "wrong number of arguments" if size <= 0 || size > 3

  case size
  when 1
    title, description = "MacRuby", args[0]
  when 2, 3
    title, description, opts = args[0 .. 2]
    if description.kind_of?(Hash)
      title, description, opts = "MacRuby", title, description
    end
  end

  opts = {} if opts.nil?
  raise ArgumentError, "illigal arguments" unless opts.kind_of?(Hash)

  g = System::Growl.instance
  icon = g.instance_variable_get(:@application_icon)

  if icon.nil?
    icon_path = File.expand_path(File.join(__FILE__, '../../../resources/macruby.icns'))
    icon = NSImage.alloc.initWithContentsOfFile(icon_path)
  end

  notification = 'notification'
  g.regist("MacRuby System Control", [notification], icon)
  g.notify(notification, title, description, opts)
end