In my previous article, we learned how to use AT commands to make phone calls and send text messages. This time, let’s look at a Ruby script that allows you to send SMS messages via AT commands.
All you need to provide the script with is the number you would like to text and the message, so it saves you the time of typing the same commands over and over again. Read my previous article for an intro to AT commands.
How does it work?
The script will run on your computer and will create a serial connection over Bluetooth. Once the connection is established, a series of AT commands are sent that instruct the phone to send a message. You’ll be asked for a phone number and the message you would like to send.
What do I need to do?
The script expects an established Bluetooth connection between your computer and your mobile device. If you haven’t paired the devices yet, this is how you do it:
1. Choose Apple menu > System Preferences and then click Bluetooth.
2. Click Add (%2B).
3. When the Bluetooth Setup Assistant comes up and you’re asked for the Device Type, select Mobile Phone.
4. The Bluetooth Setup Assistant will then start to search for mobile devices in your surroundings.
5. Turn on Bluetooth on your device.
6. Select your device from the list and continue with the setup.
Now what?
When your device is finally paired, go back to System Preferences>Bluetooth. Your device will now appear as a Bluetooth device accessible from your computer.

1. Select your phone and click on the pinwheel symbol next to the (-) minus sign and select “Edit serial ports…”
2. Click Add(%2B)
3. Give it a simple name - I called mine Jose-2.
4. For Protocol, select Modem.
5. For Service, select Dial-up Networking.
6. A device Path will show up at the bottom: in my case it’s something like:
/dev/tty.Jose-2
7. Make a note with the Path somewhere and click Apply.

You’ll also need to download the Ruby/SerialPort library from RubyForge. Mac OS X (both Tiger and Leopard) comes with a development tools bundle called Xcode. You need this tool bundle to install the Ruby/SerialPort library. If not already installed, this bundle is available on your Apple DVD. You can also download the latest Xcode version from the Apple Developer Connection.
To install the tools from the Apple DVD, follow these instructions:
1. Insert your Mac OS X Leopard/Tiger DVD.

2. You will have 3 options - one for Install Mac OS X, one folder for Optional Installs and one more folder for Instructions. Double-click the Optional Installs folder.
3. The folder has 2 more options - Optional Installs.mpkg and a folder for Xcode Tools.

Select the Xcode Tools folder and click on the XcodeTools.mpkg file. This will initiate the developer tools installation. It will take a few minutes to complete.

4. Once the OS X developer tools are installed and the Ruby/SerialPort library has been downloaded, open a Terminal window - you can find it via Finder>Application>Utility>Terminal. Then type the following commands to install the library:
$ cd Downloads/ruby-serialport-06
$ ruby extconf.rb
$ make
$ make install
5. Now that the library is installed, open your favorite text editor (TextEdit, BBedit, Textmate, etc.) and save the following script as sms_at_commands.rb:
Here is the link to the downloadable version of the script on MOSH.


How do I run the script?
Before running the script, change the “port_str” setting in the script. In my case, the setting is /dev/tty.Jose-2. Change that setting and save the script. You get this information by taking a look at your Bluetooth preferences in Applications>System Preferences>Bluetooth>Mobile Name>Edit Serial ports…>Path. Take a look at the previous post for more info.
Save the script in your “Documents” folder. Open the Terminal application and type the following command to run the script:
$ cd Documents
$ ruby sms_at_commands.rb
You’ll be asked a for the message and phone number you would like to text. Once you answer them, the phone will automatically send your message. That’s it!

I hope you find this little script useful. If you end up using it in one of your projects, please let me know in the comments section. And use the comments section to ask me any questions you have about the script or dealing with the installation of the serial library or the development tools.
Enjoy!