Class: System::Growl

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

Constant Summary

GROWL_IS_READY =
"Lend Me Some Sugar; I Am Your Neighbor!"
GROWL_NOTIFICATION_CLICKED =
"GrowlClicked!"
GROWL_NOTIFICATION_TIMED_OUT =
"GrowlTimedOut!"
GROWL_KEY_CLICKED_CONTEXT =
"ClickedContext"

Instance Method Summary collapse

Instance Method Details

#notify(notification, title, description, options = {}) ⇒ Object

Sends a Growl notification.

Parameters:

  • notification (String)

    The one of notifications that registed notifications with regist.

  • title (String)

    The title that should be used in the Growl notification.

  • description (String)

    The body of the Grow notification.

  • options (Hash) (defaults to: {})

    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.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/system_control/growl.rb', line 42

def notify(notification, title, description, options = {})
  dict = {
    :ApplicationName => @application_name,
    #:ApplicationPID => pid,
    :NotificationName => notification.to_s,
    :NotificationTitle => title.to_s,
    :NotificationDescription => description.to_s,
    :NotificationPriority => options[:priority] || 0,
    :NotificationIcon => @application_icon.TIFFRepresentation,
  }
  dict[:NotificationSticky] = 1 if options[:sticky]

  @center.postNotificationName(:GrowlNotification, object:nil, userInfo:dict, deliverImmediately:false)
end

#regist(app, notifications, icon = nil) ⇒ Object

Regists a application metadata for Growl notification.

Parameters:

  • app (String)

    The application name that should be used registration in Growl.

  • notifications (Array)

    The kind of notifications.

  • icon (NSImage) (defaults to: nil)

    The application icon that should be used registration/notification in Growl.



21
22
23
24
25
26
27
28
# File 'lib/system_control/growl.rb', line 21

def regist(app, notifications, icon = nil)
  @application_name = app.to_s
  @application_icon = icon || NSApplication.sharedApplication.applicationIconImage
  @notifications = notifications.map!{|x| x.to_s}
  @default_notifications = notifications
  @center = NSDistributedNotificationCenter.defaultCenter
  send_registration!
end