Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@oz
Created October 20, 2009 10:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oz/214140 to your computer and use it in GitHub Desktop.
Save oz/214140 to your computer and use it in GitHub Desktop.
# Simple bluetooth scan with IOBluetooth (macruby)
framework 'appkit'
framework 'IOBluetooth'
# IOBluetoothInquiryDelegate
class EventHandler
def deviceInquiryStarted(sender)
puts "Searching for devices..."
end
def deviceInquiryComplete(sender, error:error, aborted:aborted)
puts "User abort!" if aborted
puts "Scanning stopped, bye."
exit
end
def deviceInquiryDeviceFound(sender, device:device)
puts "Device found: #{device} (name: #{device.nameOrAddress})"
end
def deviceInquiryDeviceNameUpdated(sender, device:device, devicesRemaining:remaining)
puts "Update name of device #{device}: '#{device.nameOrAddress}'"
end
def deviceInquiryUpdatingDeviceNamesStarted(sender, devicesRemaining:remaining)
puts "Updating names of: #{remaining}"
sender.stop if remaining == 0
end
end
# NSApplication
class AppDelegate
def applicationDidFinishLaunching(notification)
event_handler = EventHandler.new
inquiry = IOBluetoothDeviceInquiry.new
inquiry.setUpdateNewDeviceNames(true)
inquiry.setDelegate(event_handler)
inquiry.start
end
end
# let's run. :)
app = NSApplication.sharedApplication
app.delegate = AppDelegate.new
app.run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment