Skip to content

Instantly share code, notes, and snippets.

@Watson1978
Created April 26, 2011 03:17
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Watson1978/941730 to your computer and use it in GitHub Desktop.
Save Watson1978/941730 to your computer and use it in GitHub Desktop.
MacRuby : growl
framework 'Cocoa'
framework 'Foundation'
class Growl
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"
def initialize(app, notifications, icon = nil)
@application_name = app
@application_icon = icon || NSApplication.sharedApplication.applicationIconImage
@notifications = notifications
@default_notifications = notifications
@center = NSDistributedNotificationCenter.defaultCenter
send_registration!
end
def notify(notification, title, description, options = {})
dict = {
:ApplicationName => @application_name,
#:ApplicationPID => pid,
:NotificationName => notification,
:NotificationTitle => title,
:NotificationDescription => description,
:NotificationPriority => options[:priority] || 0,
:NotificationIcon => @application_icon.TIFFRepresentation,
}
dict[:NotificationSticky] = 1 if options[:sticky]
@center.postNotificationName(:GrowlNotification, object:nil, userInfo:dict, deliverImmediately:false)
end
def send_registration!
#add_observer 'onReady:', GROWL_IS_READY, false
#add_observer 'onClicked:', GROWL_NOTIFICATION_CLICKED, true
#add_observer 'onTimeout:', GROWL_NOTIFICATION_TIMED_OUT, true
dict = {
:ApplicationName => @application_name,
:ApplicationIcon => @application_icon.TIFFRepresentation,
:AllNotifications => @notifications,
:DefaultNotifications => @default_notifications
}
@center.postNotificationName(:GrowlApplicationRegistrationNotification, object:nil, userInfo:dict, deliverImmediately:true)
end
end
if __FILE__ == $0
MESSAGE = 'notification'
g = Growl.new("MacRuby", [MESSAGE])
g.notify(MESSAGE, "Growl Test", "hello world")
end
@Watson1978
Copy link
Author

This script based on MacRuby's samle.

I do not pass :ApplicationPID, because does not work.
So can't work a callback from Growl.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment