You can quickly post a tweet from the command line using the curl command, all you’ll need is your Twitter username and password.



Launch the Terminal and type the following all on one line, replacing username and password with your own:

curl -u username:password -d status="your status message here" http://twitter.com/statuses/update.xml

I came across this via MurphyMac who used the command to schedule Twitter updates while sleeping (seriously), using the curl command in conjunction with the sleep command. I’m not sure how practical tweeting while sleeping is, but the ability to post a quick update from the command line is pretty handy.

If you’re so inclined, you can use the above command and make a quick bash script so that you can easily tweet from the command line without typing the full string. Just place the following in a text file and name it something like tweet.sh:

#!/bin/bash

curl -u username:password -d status="$1" http://twitter.com/statuses/update.xml

Be sure to specify your username and password. Then be sure to make the file executable:

chmod u+x tweet.sh

Now you’ll just need to type ./tweet.sh "I love OS X Daily" to tweet your message to the world. Thanks to Greg Mason for correcting the permissions error!

Ian Winter took the above bash script a bit further and added the ability to prevent you from posting no tweet, and a warning if a tweet is over the 140 character limit. Here is his script:

#!/bin/bash

TWEET=$1

TWEETLEN=${#TWEET}

if [ $TWEETLEN -eq 0 ] || [ $TWEETLEN -gt 140 ]; then

if [ $TWEETLEN -gt 140 ]; then

let EXTRA=$TWEETLEN-140

echo "Usage: tweet \"message\" (140 chars or less, you're $EXTRA over)"

else

echo "Usage: tweet \"message\" (140 chars or less)"

fi

exit 1

else

curl -u username:password -d status="$1" http://twitter.com/statuses/update.xml

fi

exit 0

Like before, edit your username and password, and save the file as tweet and be sure to make it executable chmod 755 tweet