Use Twitter from the Terminal (part 1)

10 03 2010

I know that this has been done to death, but I felt that I should persist in beating a deceased horse. When I am at work and don’t want it to be obvious that I am on Twitter, I use this nifty little Terminal trick that lets me send out tweets. On my laptop, I took it a step further and wrote a command-line Ruby script that does that and more.

Here are the basics of posting to Twitter through the Terminal. Somewhere on your computer, create a new shell script file. In my case, I will call it Type this into the new file:

curl -u username:password -d status="$1"
echo Message sent.

Now it is as simple as running a shell command with your message attached.

./ "Hey, I am screwing around at work!"

It is as simple as that. You can create shortcuts that make using this even easier. The most common thing I do when I write this script is to alter the .bash_profile file to save myself the trouble of typing out ./

Open a new terminal window (or tab) and enter “nano .bash_profile”. (It is not necessary that you use nano, I just prefer it for quick text editing in the Terminal.) Add the following to a new line to the file with the path in quotes being the path to your file and save.

alias tw="~/path/to/"

Now close that Terminal tab and open a new one. That is the only way to get the newly edited .bash_profile to load and your new alias to take effect. To send a message use your alias in place of ./

tw "I am screwing around at work more efficiently!"

You’re welcome.


Since I wrote this, Twitter has moved completely to OAuth for its authentication. Therefore, this shell script will no longer work. I am pretty sure there is a workaround. I just have not had time to work on it lately.




2 responses

10 03 2010

You can avoid restarting the terminal by running the “source” command. At least, it works for me in OSX.

pico .bash_profile
// add stuff to your profile and save out
source .bash_profile

I’d love to get into ruby, but I just haven’t had the time. Do you have any recommendations for a good starting point?

10 03 2010

For learning the Ruby language itself, I would check out the Ruby Lang website. There is a 20-minute tutorial on the basics of Ruby. Coming from a professional PHP background, I don’t think it would be that hard for you to pick up the basics.

As for Rails, I would take a look at the Ruby on Rails site. They have a 15-minute screencast that runs you through creating a simple blog in Rails. It really helped me get started.

RailsCasts is also an excellent resource for learning about specific Rails-oriented services, plugins, gems, etc.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: