SMS On Command Line

I ❤ SMSSometimes we as tech nerds like to do things just because we can. This is an example of exactly that. In an age where practically everyone who hasn’t been under a rock for the past decade has a smartphone which can send and receive email messages, putting in the work to allow sending old-school SMS messages, which are notoriously unreliable, from the command line is simply unnecessary. That said, it’s fun so I did it (and you can too)!

The first step you will need to take before starting is to make an account with Google Voice. Although you could also rely on an SMS gateways to handle text relay, this would first require knowing the cell provider that a number is tied to, which is often not practical.

In any event, once you have your account setup with Google Voice, the next step is to chose a language to write your SMS messaging script in. Although Google has never taken the trouble to release an official API for their messaging service, some smart individuals have figured it out and written libraries in a number of different languages. I personally chose to work in Perl and thus used WebService::Google::Voice::SendSMS, located in CPAN, but there are many other options, even other Perl libraries. A quick search for “<your chosen language> Google Voice” should return an option or two (and if not, why not write it?).

My solution for sending SMS via command line, seen at the bottom of this post, is relatively simple and leaves out some parameter checking that should probably be included for robustness, but it gets the point across. The basic idea is to first setup a config file containing your Google Voice login information in your home directory. Assuming a config file is found, the script uses the recipient’s phone number and the message to be sent, both given in the command line, to initiate the SMS message. Depending on whether the message is successfully delivered to Google or not, the program exits accordingly.

It is important to note that the program cannot determine whether the SMS message actually reached the intended recipient. This is neither a limitation of the library nor of Google Voice, but rather the SMS protocol, which cannot guarantee or verify delivery.

Once this script is complete, assuming it is named sms and the user has a config file setup, they can invoke sms <recipient #> <message> and the end user should receive the message (or at least the first 160 characters).

That’s all I’ve got for today, but I hope you found this interesting and feel free to comment on any other Google Voice libraries you’ve found or any ways that you’ve thought to use this in your day-to-day life. I’ll be posting an update soon where I discuss one use I found for this so stay tuned!

8 thoughts on “SMS On Command Line”

  1. Hi, i found this article when searching Internet.
    I tried the Perl script: made a .sms.conf file first, copied the sendsms.pm file to C:\Perl\lib\WebService\Google\Voice (active perl installed).
    But get the message:
    SendSMS: HTTP request failed: 500 Can’t connect to http://www.google.com:443 (Bad hostname) at send_sms.pl line 32.
    Any idea what might be wrong?

    P.S. I am not a developer, just a user with a little knowledge how to use Perl.

    Regrads,
    Peter

  2. wonder if something broke recently. I’ve been using this (Thanks!) for a long time and in the last 2 weeks it’s stopped working with the following:
    Unable to find _rnr_se in response at (my script) line 31

    line 31 is this:
    $sms->send_sms( $ARGV[0], $ARGV[1] ) ?
    exit 0 : exit 1;

Leave a Reply