Created
September 23, 2008 01:03
-
-
Save titanous/12196 to your computer and use it in GitHub Desktop.
NSDistributedNotifications in RubyCocoa
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
require 'osx/cocoa' | |
include OSX | |
class NotificationHandler < NSObject | |
def initialize | |
c = NSDistributedNotificationCenter.defaultCenter | |
c.addObserver_selector_name_object(self, :notification, 'com.apple.iTunes.playerInfo', nil) | |
end | |
def notification(n) | |
@data = n.userInfo # get a hash of the notification | |
if @data['Player State'] == 'Playing' | |
puts 'iTunes is playing!' | |
end | |
end | |
end | |
NotificationHandler.new | |
NSApplication.sharedApplication.run # run the Cocoa application loop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment