ZenTwitter

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.

Installation

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

Screenshots

Source

#!/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
 

Resources

Comments

1

Hi

It's very good but have some error. I replaced ]] with ] and [[ with [[ and == with = It's work correctly. Thanks for scripts.

2007/12/16 07:32
2

It should work with [[ and it should be faster than simple testing BashCuresCancer.com

2008/03/20 22:19
3

Neat and extremely convenient script! Nice work!

2008/03/27 21:05
4

I 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
5

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 :-)!

2008/04/01 10:35
6

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\""
fi
2008/08/06 22:15
7

Grrr… It ate my code. Try this instead, sorry about that, feel free to delete my previous comment.

http://pastebin.ca/1094105

2008/08/06 22:17
8

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!

2008/08/07 00:20
9

great stuff.

2008/11/21 05:27
10

Good use of zenity , no wonder why you are calling it ZenTwitter :)

2009/04/14 13:17
11

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?

ethnopunk
2009/06/30 00:45
12

It should work if you've setup your proxy environment correctly, i.e. the http_proxy environment variable etc..

2009/06/30 12:06
13

Why have you stopped developing this great program?

zen3
2009/09/21 15:34
14

Well, mainly because it's working as it is ;-) (hopefully + I don't use twitter anymore).

2009/09/21 16:08
15

It just works, if it's not broken, don't fix it. ;]

2009/09/21 17:50
16

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. ;)

zen3
2009/09/21 19:26
17

Great idea. I send my first teste.

2009/10/27 16:37
18

how do i use this thing

12355
2010/08/21 07:42
19

It's described in the installation section of this page.

2010/08/21 18:42



CGVOA