Skip to content

Instantly share code, notes, and snippets.

@titanous
Created September 23, 2008 01:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save titanous/12196 to your computer and use it in GitHub Desktop.
Save titanous/12196 to your computer and use it in GitHub Desktop.
NSDistributedNotifications in RubyCocoa
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