How to Twitter from Terminal on the Mac

UPDATE

This post is woefully out of date. Happily, Floodgap Software has released an OAuth-compatible version of a Twitter terminal/command line client, TTYtter, which is the best thing since sliced bread. I’m keeping the post below for historical reasons, but it is broken for sure.

END UPDATE

The Mac’s Terminal is the UNIX command line. It’s hard core, the stuff that Apple actually tries to keep away from the casual user. It’s the direct line to the heart of the machine, and it’s where cool scripting action can occur. Here’s how to set it up so that with a couple of key strokes, you can send a Twitter absurdly fast. You’ll need to have curl compiled and installed on your Mac as a prerequisite.

1. Copy this script to a text file named twit.sh:

#!/bin/bash
curl -u twitterusername:twitterpassword -d status="$1" http://twitter.com/statuses/update.xml

Obviously, substitute twitterusername and twitterpassword for your credentials.

2. Open Terminal and sudo chmod this file to 777.

3. Copy it to your home directory or put the location in your path.

4. Next, open up your bashrc file, which on the Mac is located at /etc/bashrc – note that you’ll have to either chmod it (bad) or sudo pico / sudo nano it to save your changes.

5. Set up an alias for the twitter script:

alias tw="/Users/yourmacusername/twit.sh"

6. Close and quit Terminal, then relaunch it. If you plan on using this a lot, you’ll probably want to put Terminal in your Dock, if it’s not there already.

7. Pop open terminal and type:

tw “Testing twitter from the command line!”

8. Check your twitter page to ensure your Tweet posted.

  • http://twitter.com/danieljohnsonjr Daniel Johnson, Jr.

    Anyone know if this or something similar works in windows?

  • http://twitter.com/danieljohnsonjr Daniel Johnson, Jr.

    Anyone know if this or something similar works in windows?

  • http://chrisbrogan.com Chris Brogan…

    That’s for outbound, right? Is there a way to “tail the log” and watch realtime status come IN?

  • http://chrisbrogan.com Chris Brogan…

    That’s for outbound, right? Is there a way to “tail the log” and watch realtime status come IN?

  • http://mcandre.wordpress.com Andrew Pennebaker

    Thanks! I added the silent option and sent the stdout text to heck:

    #!/usr/bin/env sh
    curl -u yourusername -d status=”$1″ -s -o /dev/null http://twitter.com/statuses/update.xml

  • http://mcandre.wordpress.com Andrew Pennebaker

    Thanks! I added the silent option and sent the stdout text to heck:

    #!/usr/bin/env sh
    curl -u yourusername -d status=”$1″ -s -o /dev/null http://twitter.com/statuses/update.xml

  • http://carlos-presencia.blogspot.com/ carlos

    Hi,
    I work with ubuntu 7.10
    I’ve follow the steps but when I type in the terminal:
    tw
    and ask for my host password I enter my twitter pass, but it says:
    Couldn’t resolve host
    The host pass and the twitter pass are different?
    Thanks

  • http://carlos-presencia.blogspot.com/ carlos

    Hi,
    I work with ubuntu 7.10
    I’ve follow the steps but when I type in the terminal:
    tw
    and ask for my host password I enter my twitter pass, but it says:
    Couldn’t resolve host
    The host pass and the twitter pass are different?
    Thanks

  • http://carlos-presencia.blogspot.com/ carlos

    Now, works fine. I don’t know what’s happened.
    Only to add the script works in gnu/linux OS too
    Regards

  • http://carlos-presencia.blogspot.com/ carlos

    Now, works fine. I don’t know what’s happened.
    Only to add the script works in gnu/linux OS too
    Regards

  • http://murphymac.com Murphy Mac

    Does this not work with the curl that ships with Leopard? I left my password out of the command, was prompted for it, but my post didn’t appear. I saw the html go by.

    Cool. I’ll be looking into Chris Brogan’s question. I’m definitely interested in seeing Tweets in the Terminal.

  • http://murphymac.com Murphy Mac

    Does this not work with the curl that ships with Leopard? I left my password out of the command, was prompted for it, but my post didn’t appear. I saw the html go by.

    Cool. I’ll be looking into Chris Brogan’s question. I’m definitely interested in seeing Tweets in the Terminal.

  • http://www.ChristopherSPenn.com Christopher S. Penn

    Dunno – as a rule, I typically compile major packages I know I’m going to use from source. That’s a me oddity :)

  • http://www.ChristopherSPenn.com Christopher S. Penn

    Dunno – as a rule, I typically compile major packages I know I’m going to use from source. That’s a me oddity :)

  • http://celo.wordpress.com crimeboy

    to improve that, and use without commas i make it

    crimeboy@groselia:~$ cat twi
    #!/bin/bash
    # requires curl
    ###########################

    ######## CONFIG
    USER=YOULOGIN
    PASS=YOURPASS
    URL=”http://twitter.com/statuses/update.xml”
    ###############
    curl -u $USER:$PASS -d status=”$*” -s -o /dev/null ${URL}

  • http://celo.wordpress.com crimeboy

    to improve that, and use without commas i make it

    crimeboy@groselia:~$ cat twi
    #!/bin/bash
    # requires curl
    ###########################

    ######## CONFIG
    USER=YOULOGIN
    PASS=YOURPASS
    URL=”http://twitter.com/statuses/update.xml”
    ###############
    curl -u $USER:$PASS -d status=”$*” -s -o /dev/null ${URL}

  • Jesse

    Hello,

    I like you script, its simple and sweet. I only have to say that its probably not a good idea to advise people to chmod something to 777. This would enable other users (who would have access to your machine or network) to see not only the password which is hard coded in the script, but to change the script and insert something malicious. Perhaps something a bit more conservative like 700 would be a better choice. This value would mean that the owner (you) has read, write and execute permissions on the file, but no one else. I know you probably, and rightfully trust the people on your network, but hey–its the same amount of typing and you get free security :) .

    Kind Regards,

    Jesse

  • Jesse

    Hello,

    I like you script, its simple and sweet. I only have to say that its probably not a good idea to advise people to chmod something to 777. This would enable other users (who would have access to your machine or network) to see not only the password which is hard coded in the script, but to change the script and insert something malicious. Perhaps something a bit more conservative like 700 would be a better choice. This value would mean that the owner (you) has read, write and execute permissions on the file, but no one else. I know you probably, and rightfully trust the people on your network, but hey–its the same amount of typing and you get free security :) .

    Kind Regards,

    Jesse

  • Bonnie

    This looks great. I don’t know anything about compiling commands so I tried the curl that comes with OS X. When I try this only the content up to my first space is posted on Twitter. Do you think that’s my curl or is there something else you think it might be?

  • Bonnie

    This looks great. I don’t know anything about compiling commands so I tried the curl that comes with OS X. When I try this only the content up to my first space is posted on Twitter. Do you think that’s my curl or is there something else you think it might be?

  • Bonnie

    Huh, my quotes looked funny around the $1 – I created the text file using the cat command. Fixed the quotes with pico, they look right now, and it works. Thanks.

  • Bonnie

    Huh, my quotes looked funny around the $1 – I created the text file using the cat command. Fixed the quotes with pico, they look right now, and it works. Thanks.

  • http://twitter.com/murkee Murk

    I think this is now broken due to OAuth.

  • http://www.ChristopherSPenn.com Christopher S. Penn

    Post updated!