ZenTwitter is a small script I wrote to be able to update my twitter account without the need of having a browser window open all the time. It uses zenity and curl.
Just dump it into your ~/bin directory, open it in the editor of your choice to change the username/password, make it executable (chmod a+x) and add a launcher icon to the panel/menu/desktop of your preferred window manager.
Download: ZenTwitter.tgz
#!/bin/bash # @author Michael Klier <chi@chimeric.de> # @www http://www.chimeric.de/pojects/ZenTwitter # trivial twitter status update client # set username/password USER="username" PASS="password" # main script URL="https://twitter.com/statuses/update.xml" ZENITY=/usr/bin/zenity CURL=/usr/bin/curl # check if zenity is installed if [[ ! -x $ZENITY ]]; then echo "ERROR: Zenity is missing!" exit 1 fi # check if curl is installed if [[ ! -x $CURL ]]; then $ZENITY --error --text="ERROR: curl is missing" --title="ZenTwitter" exit 1 fi # get tweet tweet=$(${ZENITY} --entry --text="Gimme your tweet:" --title="ZenTwitter") if [[ "$?" == 1 ]]; then exit 0 fi while [[ $(echo "${tweet}" | tr -d ' ') == "" ]]; do tweet=$(${ZENITY} --entry --text="D'oh! You entered nothing! Try again or cancel:" --title="ZenTwitter") if [[ "$?" == 1 ]]; then exit 0 fi done # update status $CURL -u ${USER}:${PASS} -d status="${tweet}" ${URL} -k if [[ "$?" == 0 ]]; then $ZENITY --info --text="Updated successful!" --title="ZenTwitter" exit 0 else $ZENITY --error --text="Something went wrong!\nRun ZenTwitter.sh from a commandline for more information!" --title="ZenTwitter" exit 1 fi
It should work with [[ and it should be faster than simple testing BashCuresCancer.com
2008/03/20 22:19I needed to modify the interpreter to #!/bin/bash in Ubuntu because I was getting the same double bracket errors as Saeid - at least I think that's what was happening.
https://wiki.ubuntu.com/DashAsBinSh
Otherwise, works great. Great job.
2008/04/01 02:18
Aaaah, hmmm, seems I've missed to change that in the tarball (I've changed that in the source code listing on this site a while ago). Thanks for the hint
!
Here is the code I use, very similar, except that it checks the length. Twitter doesn't allow “twits” longer than 140 characters.
You'll need to export/define your username/password as well.
if [ $# != 0 ]; then export status="$*"; fi if [ $# = 0 ]; then export status="`zenity --entry --title \"Twitter\" --text \"What are you doing?\"`" fi export count=`echo "$status" | wc -m`; echo $count; if [ $count -gt 140 ]; then zenity --error --title "Twitter" --text "Your status was over 140 characters." exit; fi if [ -z "$status" ]; then zenity --error --title "Twitter" --text "Your status wasn't changed." exit; else curl -u $username:$password -d status="$status" http://twitter.com/statuses/update.xml zenity --info --title "Twitter" --text "Your status was updated to \"$status\"" fi2008/08/06 22:15
Grrr… It ate my code. Try this instead, sorry about that, feel free to delete my previous comment.
2008/08/06 22:17
No problem, I've edited it to conform to the syntax used here
(I really should put some notes about that here). Thanks for your commen!
It asked me for tweet, and then after a while this error: curl: (7) couldn't connect to host
Is there a way to use this via a proxy?
It should work if you've setup your proxy environment correctly, i.e. the http_proxy environment variable etc..
Well, mainly because it's working as it is
(hopefully + I don't use twitter anymore).
I button to see your updates would be good.
[Click me for your updates] and this can redirect you to → http://twitter.com.
It's ideal position would be under Cancel And Ok button, coz it's big. ;)
Hi
It's very good but have some error. I replaced ]] with ] and [[ with [[ and == with = It's work correctly. Thanks for scripts.