# Bluetooth on OSX

**URL:** <https://www.ruby-forum.com/t/bluetooth-on-osx/49046>\
**Category:** Ruby\
**Created:** [November 29, 2005, 6:54am UTC](https://www.ruby-forum.com/t/bluetooth-on-osx/49046 "2005-11-29T06:54:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rictic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/3d9bf3/32.png) [@rictic](https://www.ruby-forum.com/u/rictic)\
**Post date:** [November 29, 2005, 6:54am UTC](https://www.ruby-forum.com/t/bluetooth-on-osx/49046/1 "2005-11-29T06:54:59Z")

</div>

I’m looking to automate transferring pics from a cellphone via bluetooth  
on  
OS X. Any suggestions on where to start with this project? Ruby is the  
natural language for this, not just because I love it so dearly, but  
because  
I hope to integrate this with a Rails photo gallery app.

My google-fu is failing me on relevant libraries, ruby or otherwise.

---

<div class="post-metadata">

**Author:** ![rictic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/3d9bf3/32.png) [@rictic](https://www.ruby-forum.com/u/rictic)\
**Post date:** [November 29, 2005, 7:23am UTC](https://www.ruby-forum.com/t/bluetooth-on-osx/49046/2 "2005-11-29T07:23:18Z")

</div>

On 11/29/05, Peter B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’m looking to automate transferring pics from a cellphone via bluetooth on  
> OS X. Any suggestions on where to start with this project? Ruby is the  
> natural language for this, not just because I love it so dearly, but because  
> I hope to integrate this with a Rails photo gallery app.
> 
> My google-fu is failing me on relevant libraries, ruby or otherwise.

I have no experience in this area at all, but i remember seeing a  
cellphone bluetooth XMMS remote control program on RAA, so I looked it  
up for you:

[http://linuxbrit.co.uk/bluexmms/](http://linuxbrit.co.uk/bluexmms/)

You might be able to tear the protocol stuff out of there and modify it.  
HTH

---

<div class="post-metadata">

**Author:** ![rictic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/3d9bf3/32.png) [@rictic](https://www.ruby-forum.com/u/rictic)\
**Post date:** [November 29, 2005, 9:28am UTC](https://www.ruby-forum.com/t/bluetooth-on-osx/49046/3 "2005-11-29T09:28:27Z")

</div>

In article  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid),  
Peter B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’m looking to automate transferring pics from a cellphone via bluetooth on  
> OS X. Any suggestions on where to start with this project? Ruby is the  
> natural language for this, not just because I love it so dearly, but because  
> I hope to integrate this with a Rails photo gallery app.
> 
> My google-fu is failing me on relevant libraries, ruby or otherwise.

gnokii ([www.gnokii.org](http://www.gnokii.org)) works for me from the command line. A simple  
ryby script around it is:

```
info = `gnokii --monitor once`

numUnreadSMSes = 0
numSMSes = 0

info.scan( /^SMS Messages: Unread ([0-9]+), Number ([0-9]+)/) { 

```

|x,y|  
numUnreadSMSes = x  
numSMSes = y  
}

```
puts numUnreadSMSes
puts numSMSes

```

Aside: I may not be possible at all to transfer pictures from your phone  
over Bluetooth. Mobile operators would rather have you use MMS to mail  
them to yourself.

Reinder

---

<div class="post-metadata">

**Author:** ![rictic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/3d9bf3/32.png) [@rictic](https://www.ruby-forum.com/u/rictic)\
**Post date:** [November 29, 2005, 12:34pm UTC](https://www.ruby-forum.com/t/bluetooth-on-osx/49046/4 "2005-11-29T12:34:55Z")

</div>

Thanks for the two wonderful replies, this just turned a wishful  
thinking project into something that I could have working in a couple  
hours.

I can use the Bluetooth File Exchange app to grab pictures off of my  
mobile (that was definitely something I was looking for in a phone; I  
wasn’t going to pay a dollar a piece for the privilege of emailing  
myself my own pictures), so I’m confident that if I can’t wrangle  
gnokil to access the pics, I’ll be able to by talking to the Bluetooth  
File Exchange app.

I’ll post the code here once I get it working and perhaps it will help  
someone else along.

---

<div class="post-metadata">

**Author:** ![rictic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/3d9bf3/32.png) [@rictic](https://www.ruby-forum.com/u/rictic)\
**Post date:** [November 29, 2005, 11:34am UTC](https://www.ruby-forum.com/t/bluetooth-on-osx/49046/5 "2005-11-29T11:34:10Z")

</div>

A simple way to do it is using RubyCocoa. RubyCocoa offers two  
solutions. Either through the usage of its AppleScript bridge. With  
embedded AppleScript it becomes possible to control the application  
“Bluetooth File Exchanger” inside the “Utilities” folder.

…or you use native cocoa classes inside your Ruby code. This approach  
requires some knowledge about OBEX. Have a look into the application  
OBEXSample inside /Developer/Examples/Bluetooth !

Finally it will look similar to this

* * *

require ‘osx/cocoa’

OSX::NSBundle.bundleWithPath("/System/Library/Frameworks/IOBluetoothUI.framework").load  
OSX.ns\_import :IOBluetoothDeviceSelectorController

## bluedevices = OSX::IOBluetoothDeviceSelectorController.deviceSelector bluedevices.runModal blue\_data = bluedevices.getResults puts blue\_data

- Tom
