URL: http://snipplr.com/view/2352/twitter-from-the-command-line-using-curl/
The Twitter shell script is now hosted on GitHub. This (old) version is left in place for historical purposes.
Put this in a file called tweet.rb, then call as follows: ruby tweet.rb username "my tweet"
Or you can include your password in the command like so ruby twit.rb username:password "my tweet"
(note that this is hugely insecure as your password will wind up in your .history, not to mention being visible to shouldersurfers).
Updated: if a post is over the 140-character limit, the script prints back the part of the tweet that would not fit. This makes it easier to trim down overly long posts.
#!/usr/bin/env ruby #Usage: # ruby tweet.rb username:password "status message" def tweet (arguments) user, twit = arguments response = `curl -s -u #{user} -d status="#{twit}" http://twitter.com/statuses/update.xml | grep truncated` unless (response =~ /truncated>false</) puts "fail: Tweet failed. Check your user name and password." end end if (ARGV[1].length > 140) overlimit = ARGV[1].length - 140 offendingSubstring = ARGV[1][140, ARGV[1].length-1] puts %Q{FAIL: #{overlimit} characters over the 140-character limit:} puts %Q{\t"...#{offendingSubstring}"} elsif (ARGV.length != 2) || (ARGV[1] == "") puts %Q{usage: ruby tweet.rb <username> "This will be tweeted to Twitter."} else tweet(ARGV) end
Comments
Subscribe to comments
You need to login to post a comment.

Awesome, Noah. Thanks.
hi friend, do you know cheap ghd, cheap mbt shoes, christian louboutin shoes hot sell online recently?
we are china wholesaler company, offer good quality nike dunks, ghd mk4, cheap soccer jerseys online, cheap jerseys online enjoy much discount.cheap nike dunks,nike shox why are you hestitate, welcome for retail, dropship, and wholesale orders.