Created
April 26, 2011 03:17
-
-
Save Watson1978/941730 to your computer and use it in GitHub Desktop.
MacRuby : growl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script based on MacRuby's samle.
I do not pass :ApplicationPID, because does not work.
So can't work a callback from Growl.