Send an SMS Text Message from the Command Line

Mar 12, 2014 - 29 Comments

Send a text message from the command line When you think of sending out text messages you probably think of the iPhone or an Android, and the command line doesn’t cross your mind, but thanks to the ever-useful curl command, you can send out a SMS text message to any phone number right from the Terminal.

Yes, curl, the same command line tool for transferring data to and from URL’s, downloading files, getting HTTP header details, and so much more, can send text messages. This is done through a POST request sent to the TextBelt service, a free outgoing SMS API. Sure there are limits, but they’re fairly generous at 75 texts per day (per IP), and you can’t send a number more than 3 texts in three minutes to prevent abuse. Aside from that, keep in mind that you’ll be charged for incoming texts at the regular SMS / texting rate from your cell provider – this does not use the iMessage service – so don’t overuse this if you don’t have an unlimited traditional texting plan.

Sending a Text Message from the Command Line with curl

The basic syntax to use is as follows, be sure to replace the ########## with your own 10 digit phone number (10 digits = area code + phone number), and then replace the message= text with your own message to send:

curl http://textbelt.com/text -d number=########## -d "message=text goes here"

For example, to send a text saying “hello from OSXDaily.com” to the phone number 555-155-1555 (not a real number), you would use the following command string:

curl http://textbelt.com/text -d number=5551551555 -d "message=hello from OSXDaily.com"

Yes you could put another persons phone number in there too, but you probably should not do that without their permission.

If the text was successfully sent, the command line will return a message stating ‘{“success”:true}’, if it fails for whatever reason, it’ll look something like the following, which is usually indicative of an error in your command syntax: ‘{“success”:false,”message”: “Number and message parameters are required.”} curl: (6) Could not resolve host:’ Just review the command string and try again.

The text message should arrive to your iPhone or Android very quickly, though the expedience of the service likely depends on a queue and how much activity TextBelt is receiving from elsewhere. It’ll come through looking something like the following:

SMS texts on an iPhone as sent from TextBelt command line service

(If you’re wondering, responding to the texts goes nowhere and does nothing, it’s not a 2-way service)

This works to send texts from Mac OS X, Linux, and presumably whatever other OS or service has curl access. The recipient side should work with any mobile phone that accepts SMS, whether it’s an iPhone or an ancient brick Nokia.

Adding a Quick ‘Send Text’ Command to Bash

If you enjoy the convenience of sending yourself texts from the terminal and plan on using this often, you can create a simple bash script to shorten the command string by adding the following to your .bash_profile. Be sure to replace the number with your 10 digit phone number:

sendtext () { curl http://textbelt.com/text -d number=5551113333 -d "message=$1";echo message sent; }

With that in your bash_profile, you can simply type “sendtext your message goes here” to send out a text to yourself. This also allows for some fun and utility with double ampersands &&, like sending yourself SMS alerts when a software package has finished installing, or when a remote file is done downloading. Those with command line experience can probably think of a million and one other handy uses for this as well.

According to TextBelt, the service definitely works within the USA with the following cell networks: Alltel, Ameritech, AT&T Wireless, Boost, CellularOne, Cingular, Sprint PCS, Telus Mobility, T-Mobile, Metro PCS, Nextel, O2, Orange, Qwest, Rogers Wireless, US Cellular, Verizon, Virgin Mobile. This may be limited to the USA, but we’re unable to test networks outside of the region, let us know if you give it a try elsewhere.

Enjoy this tip? Subscribe to the OSXDaily newsletter to get more of our great Apple tips, tricks, and important news delivered to your inbox! Enter your email address below:

Related articles:

Posted by: Paul Horowitz in Command Line, Mac OS X, Tips & Tricks

29 Comments

» Comments RSS Feed

  1. Mike says:

    Wow this is cool, great trick!

  2. Kayne says:

    Doesn’t work on Polish numbers (here we have 9 digits number and 2-3 for country code). So it returns {“success”:false,”message”:”Invalid phone number.”}.

    • Junior Jr says:

      It works in USA and Canada only, apparently. Maybe Mexico too if you can stay on a US cell tower, heh.

      Anyway, this is cool, I will use it for notifications!

  3. Leslie says:

    Maybe only in the US.I tried to send to a swedish mobile but I got “Invalid phone number”

  4. joe user says:

    now could a spammer use this? send out hundreds of these things. no trace back only the poor site that just get bombarded by text messages…

    i could see it now
    FRM:txt@textbelt.com
    MSG:Sign up for Russian brides at http://www.fakewebsite.scammer

    • Junior Jr says:

      Probably not with “75 texts per day (per IP)”

      If you’re a bulk SMS sender, there are services which offer many thousands a day. Or you can just use AIM (yes, AOL Instant Messenger! LOL!!!), because you can send endless texts through the AIM service by prefixing a message with +1

  5. Marc says:

    Worked for AT&T of course, but did not work for my Google Voice number. :(

  6. @ngel says:

    Doesn’t work in the UK either

  7. Corrie says:

    The textbelt website confirms that they only support some US carriers (network operators).

  8. Chris says:

    Does not work in Germany:
    {“success”:false,”message”:”Invalid phone number.”}

  9. Tedy says:

    Apparently it doesn’t work for Indonesian number with 62 prefix

    {“success”:false,”message”:”Invalid phone number.”}

  10. Luis says:

    Doesn’t work in Spain either : /

  11. mobilio says:

    This is same gateway that we use for SendSMS app http://www.mobiliodevelopment.com/sendsms-osx/

    But you’re correct – works only on few US and Canada operators.

  12. Federico says:

    Who are the people behind textbelt.com? why should we trust them?

    • Don says:

      Exactly what do you need to trust them with? The destination phone number? The message? I simply wouldn’t text anything this way that I wasn’t prepared to be seen by at least some people, if not the world. But that’s largely my attitude about any text.

  13. Romeo says:

    Ukraine, doesn’t work :(

  14. Me says:

    Is there a way too to send a fax with Curl?
    Would be cool!

  15. Tim says:

    Some carriers (like Verizon) allow blocking of texts from the web and email. If you have that turned off, you won’t get these.

  16. Jason Tsai says:

    doesn’t seem to be working here in Toronto.

  17. .- says:

    The title “Send an SMS Text Message from the Command Line” is misleading. It should read “Using a web service from command line”. The command line does not send a text in this case.

  18. Pol Wirtz says:

    Doesn’t work in Luxembourg – but anyway: the “regular” approach is so much simpler to me :-) !

  19. Brett Rossi says:

    would you mind if I post this on twitter?

  20. Mike says:

    The source code on GitHub suggests you can also do this yourself without having to go through TextBelt

    where %s = your phone number

    list: [
    ‘%s@message.alltel.com’,
    ‘%s@paging.acswireless.com’,
    ‘%s@txt.att.net’,
    ‘%s@myboostmobile.com’,
    //’%s@sms.edgewireless.com’, // slow
    ‘%s@messaging.sprintpcs.com’,
    ‘%s@tmomail.net’,
    ‘%s@mymetropcs.com’,
    ‘%s@messaging.nextel.com’,
    ‘%s@mobile.celloneusa.com’,
    ‘%s@qwestmp.com’,
    ‘%s@pcs.rogers.com’,
    ‘%s@msg.telus.com’,
    ‘%s@email.uscc.net’,
    ‘%s@vtext.com’,
    ‘%s@vmobl.com’,
    ‘%s@txt.windmobile.ca’,

    https://github.com/typpo/textbelt/blob/master/providers.js

  21. Vijay says:

    If you want this to be even cooler, put this in your bash_profile:

    sendtext () {

    var=$*
    var=${var#*$1}

    curl http://textbelt.com/text -d number=$1 -d “message=$var”;
    echo message sent;

    }

    This allows you to type “sendtext typephonenumberhere write your message here”. This way you can send custom messages to custom numbers without having to change your bash_profile every time!

    • Douc Gleason says:

      I like this idea and so I am using it with vim but now I am stuck and can’t quit out of vim. Ended up using kill -9 LOL!!

      Why is vim the hardest thing ever? I guess I’ll use something else…

      • Paul says:

        We see this question a lot, the easiest way to quit out of vim is: Escape, SHIFT ZZ

        Write-up coming up, I think it will help many. Generally most users are better off using nano or, depending on what they’re editing, even TextWrangler in the GUI.

  22. Bob says:

    Does not work with Australian numbers.

  23. Sam says:

    Doesn’t work on Mars either :-(

Leave a Reply

 

Shop for Apple & Mac Deals on Amazon.com

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates