annabunches.net/content/posts/2009-07-02-twitter-from-command-line.html

18 lines
2.0 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
excerpt_separator: <br/>
category: technology
layout: post
title: Twitter from the command line
date: '2009-07-02T11:38:00.000-04:00'
author: Anna Wiggins
tags:
- programming
- linux
- twitter
- Technology
modified_time: '2013-10-22T11:19:50.705-04:00'
blogger_id: tag:blogger.com,1999:blog-4209116010564764361.post-6156350980105195782
blogger_orig_url: http://www.stringofbits.net/2009/07/twitter-from-command-line.html
---
I've recently started playing with twitter. A nice way to use it via the command-line (using curl) was suggested <a href="http://binnyva.blogspot.com/2007/03/using-twitter-part-1-command-line.html">here</a>. I have taken that and improved slightly on it.<br/><br/><a name='more'></a><br/><br/>Here is the result:<br/><br/><blockquote><code>#!/bin/sh<br/>echo -n "twitter&gt; "<br/>read text<br/><br/>while [ ${#text} -gt 140 ]; do<br/><br/>echo<br/>echo "Message too long; used ${#text}/140 characters."<br/>echo<br/>echo -n "twitter&gt; "<br/>read text<br/><br/>done<br/><br/>echo<br/>echo "Message is ${#text}/140 characters.  Press enter to post, or Ctrl+C to cancel."<br/>read<br/><br/>curl --basic --user "username:password" --data-ascii "status=`echo $text|tr ' ' '+'`" "http://twitter.com/statuses/update.json" &amp;&gt; /dev/null<br/></code><br/></blockquote><br/><br/>To use the script, copy all of that into a file somewhere in your path, then make the file executable (e.g., <code>chmod 755 /usr/local/bin/twitter</code>).  Now you can type 'twitter', type in your tweet, and you're done!<br/><br/>I even set up fluxbox so that mod4+t launches a terminal with the script running.  To do that, I added this to ~/.fluxbox/keys:<br/><br/><blockquote><br/><code><br/>Mod4 t :Exec xterm -e "twitter"<br/></code><br/></blockquote><br/><br/>If you're not familiar with 'mod4', it is the Windows key on most PC keyboards.<br/><br/>I'll eventually get around to writing a slightly more full-featured twitter updater in c or c++.  Until then, enjoy this script!