Tweeting To Twitter From Terminal 19
Terminal
Hey
I love Twitter. Its such a good service. I think of it as Instance Messenger for the world. If you want to follow me, you can find my profile here. This post is going to be a little post which you can use Tweet anything from Terminal. Its useful if you want to set up a program or script to send results to Twitter. Its really simple to do. I’ll show you a quick one line method and a quicker method if you want to use this option more frequently.
The code is very simple. Basically it will send a specially command to Twitter on the update URL. This update URL will contain your message. On the face of it this command isn’t very secure, but it is useful if you want to send system messages as part of scripts to Twitter.
In Terminal type the following replacing the specific data as you need.
curl -u username:password -d status="message" http://twitter.com/statuses/update.xml
Simple one line. Very simple. It does work, for example this twitter post was made using this command.
If you think you will use this command quite frequently you can add it into a file. Open a new text document and add the following, save it as twitter.sh (or anything ending in sh)
#!/bin/bash
curl -u username:password -d status="$1" http://twitter.com/statuses/update.xml
Make sure you change the chmod to 777 using the following command.
chmod 777 /path/to/file/
When you located the file (or add a bash prompt) it makes it simplier to twitter the rules. For example you can type the following to command to link to the file.
./path/to/twitter.sh "Message"
or with .bashrc
tw "Message"
A cool little Terminal trick which I might use more frequently.
If you want to find out a bit more about Twitter and want to read a good book I recommend these two on Amazon, Twitter For Dummies and Twitter Means Business. Both are good books and I recommend you check them out.
Where To Next?
19 Responses to “Tweeting To Twitter From Terminal”
-
1
That is defiantly very cool!
Comment By GG on January 29th, at 11:04 pm
-
2
Its a cool little trick, I like using it. I might make some scripts which incorporate it.
Comment By admin on January 29th, at 11:06 pm
-
3
One small problem when i tried to use it it said
/twitter.sh: line 1: {rtf1ansiansicpg1252cocoartf949cocoasubrtf430: command not found
/twitter.sh: line 2: syntax error near unexpected token `}’
/twitter.sh: line 2: `{\fonttbl\f0\fswiss\fcharset0 Helvetica;}’any ideas?
Comment By GG on January 29th, at 11:17 pm
-
4
Sounds like you are using rich text. Change text edit to normal text and re-save. Makes sure the chmod is 777.
Comment By admin on January 29th, at 11:19 pm
-
5
Why in the world would you want to make a file with your username and password (clear text no less) group and world readable? Not knowing how to use keychain, it would be better to make username and password variables that are filled by:
echo -n “username: ”
read username
echo -n “password: ”
stty -echo
read password
stty echoThere should be a way to use keychain to do something more elegant.
Comment By Anonymous on January 29th, at 11:53 pm
-
6
Thats why I said it was insecure. I didn’t know how to use keychain, sounds a good plan to implement.
Comment By admin on January 29th, at 11:55 pm
-
7
great post! this is very cool.
you could also set up an alias
alias twitter=”/Users/dkeegan/twitter.sh $1″
so you can type: twitter “message” from anywhere
Comment By David Keegan on January 30th, at 2:05 am
-
8
How can I give a tweet with the source for example “Terminal”.
Default tweets have the source “web”, “IM”, “phone” or “Twitterific”Comment By Marco Koch on March 6th, at 11:36 pm
-
9
@Marco, you will have to play with the API. I think you have to be a registered developer to change the source.
Comment By admin on March 9th, at 3:17 pm
-
10
What’s a terminal?
Comment By yy1993 on July 25th, at 1:23 pm
-
11
Thanks for sharing this, it will really improve my use of twitter.
Comment By farbige kontaktlinsen on October 20th, at 5:57 pm
-
12
really nice article, thanks ! also read this: http://www.citrusblog.net/tweetit-0-1-free-twitter-programm/
Comment By CitrusBlog on December 19th, at 4:01 pm
-
13
Hmm..cool.. Does it work on Linux?
Comment By Gojeg on January 2nd, at 3:11 pm
-
14
That’s cool!
Comment By Ye Myat on March 6th, at 8:07 pm
-
15
so this is broken… do we have a fix??
Comment By Jake on November 24th, at 12:52 am
-
16
You should totally use console_tweet, a ruby application I wrote for tweeting from the console (with OAuth support)
Comment By John Crepezzi on December 30th, at 7:57 pm
-
17
i get this error:
Basic authentication is not supported
Comment By neco on January 29th, at 1:59 am
-
18
Twitter changed authentication protocols to OAuth. This will no longer work.
Comment By cooldude on April 23rd, at 8:10 pm
-
19
well nice tips..
but unfortunately i can’t use it, mine saysBasic authentication is not supported
any idea why is that?
Comment By mario on September 25th, at 10:27 am