Subscribe     RSS   MOBILE   EMAIL  
Subscribe to Workshop! It's fun.
Go ahead, pick a reader:
Add to Google
Add to Yahoo
Add to Bloglines
Add to Rojo
Add to Newsgator
Add to Netvibes
RSS Feed
Feed URL:
http://workshop.nseries.com/feed
Scan this code or type this link in your browser for the mobile RSS feed:
http://workshop.nseries.com/feed
Sign up for Workshop emails!
Categories
Archives
Loading
 
06 Mar 2008
 
Tags
 

big pic

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!

 
share          
email   share        print   print       
Comments (8)
Ed
9:43 PM
09.22.08



Hi! This is an great little script! I have missed the SMS bluetooth functionality I used to have back in MacOS Panther with my Sony-Ericsson T68i ( you could click a bluetooth icon in the addressbook, and it would connect to your phone, and let you send sms messages direct from the addressbook ( as well as send messages to the screen of the mac telling you if you had a call, and letting you answer it from the mac ). Apple took this out of Tiger and Leopard, which kind of stinks ( I don't know if you can do it with the iPhone, I don't have one ). Anyway, this little script is just what I have been looking for!! Thanks again!!


Red
7:55 PM
02.03.09



Hey! Wonderful article! But I am not clever enough to arrange what I need. :-( How do I make an apple-script (or whatsoever) for my Adium, that will send an sms when I receive a message? I know it should be possible.


Alexwebmaster
5:30 AM
03.03.09



Hello webmaster I would like to share with you a link to your site write me here preonrelt@mail.ru


Eric
5:49 AM
03.12.09



Great block of code. I used it in a reservations management system written in Ruby Cocoa. Sends SMS reminders out to everyone who has bookings. One thing that took me a little while to work out was that you had to wait for the serialport connection to be setup and torn down. Otherwise no message came through when looping through a help of results... ie for result in results setup serial connection sleep send message close serial port sleep end


Bluetooth Phone, Ruby & Timeouts on Serial Ports - Cosmic7600.com
10:04 PM
03.12.09



[...] http://workshop.nseries.com/2008/03/how-to-send-sms-from-os-x-with-at-commands-and-ruby/170 [...]


Oscar
7:11 AM
03.25.09



I can't get this nor the oter tutorial to work with my SonyEricsson phone. Does anyone know how to send msges if you don't have a nokia?


FXsix
11:34 AM
07.09.09



Doesn't work under 10.5.7? Tried on both Intel and PPC and got nothing after "ruby sms_at_commands.rb"... The link to MOSH is broken, so I created the .rb file from your JPG and change my port... maybe I'm missing something from the sms_at_commands.rb file?: require "serialport.so" #parameters for serial port port_str="/dev/tty.NoK-3" baud_rate = 9600 data_bits = 8 stop_bits = 1 parity = SerialPort::NONE sp = SerialPort.new(port_str, baud_rate, data_bits, stop_bits, parity)


Gangster54
2:35 PM
10.10.09



Opportunity is truly equal as a minimum. ,


 
 
 
Enter comment
Name


Email (not displayed publicly)
 
Related Posts
feature mini
Useful applications for your N96
feature mini
How to use Mobile Web Server: Part 3
feature mini
Q&A with Chris Bennett from America’s Emergency Network
 
Workshop Mobile Code
 
Location:         Language: English