How to show Twitter mentions in Conky

You can pipe just about anything to Conky and your Twitter mentions are no exception. We do need to consider the Twitter api’s request limit though. At the day I am writing this that limit is 15 requests per 15 minutes. I believe Twitter’s website, TweetDeck and TweetDeck’s web and app versions are not taken into account towards the limit. Still I recommend being conservative with Twitter api requests, just to be sure.

I’m using Debian Wheezy but you should be good to go on Ubuntu and other Debian derivatives (e.g. Linux Mint) as well and other distros.

Conky showing Twitter mentions
Conky showing Twitter mentions

Here’s how we’ll go about it:
1. Set up TTYtter, a Perl and command line based Twitter client.
2. Use a script to periodically retrieve your mentions.
3. Set up Conky and have it show your mentions.

Install TTYtter
Download TTYtter from this site: The script is usually called <VERSIOM>.txt. At the moment of writing the latest version is 2.1.00.

$ wget

Rename and move the script to a logical name and place:

$ sudo cp 2.1.00.txt /usr/bin/TTYtter

Make the script executable

$ sudo chmod +x /usr/bin/TTYtter

Set up your Twitter account in TTYtter

$ ttytter

Now follow the on-screen instructions about allowing TTYtter to use your account.

wheezy (Working Conky) -14-30_19

wheezy (Working Conky) -14-30_31

Setting up your Twitter account in TTYtter
Setting up your Twitter account in TTYtter

Start TTYtter and make sure it is working.

$ ttytter -vcheck

-vcheck tells the client to look for updates to the script.

If it complains about SSL try

$ ttytter -vcheck -ssl

Type /quit to quit your interactive TTYtter Twitter session.

Use a command to print your last four mentions:

$ echo "/replies +4" | TTYtter -script -notimeline -ssl

Your last four mentions should appear in your terminal. If it doesn’t, troubleshoot until it does. Keep in mind you are allowed 15 requests per 15 minutes.

Now we *could* add this to ~.conkyrc:

${exec echo "/replies +4" | TTYtter -script -notimeline -ssl}

The problem: by default Conky updates every second. TTYtter needs a couple of seconds (let’s say 6) to pull your mentions from the database. This means that after about a minute and a half you’d have burnt your alotted db requests.

We work around this by writing a little shell script to pull your mentions from the db and write them to a local file, then having Conky read that file. We’ll store everything nicely away in a hidden folder so you can forget about it later.

The script

Create a folder ~/.conky

$ mkdir ~/.conky
$ cd ~/.conky

(The accountname I’m using on my test machine is ‘test’. Its home folder is /home/test/. Adapt the following accordingly.)

Create the file and write this in it:

echo "/replies +4" | TTYtter -script -notimeline -ssl > /home/test/.conky/newreplies.txt
if [ -s /home/test/.conky/newreplies.txt ]; then
  mv /home/test/.conky/newreplies.txt /home/test/.conky/replies.txt

We need to use absolute paths to prevent confusing Cron.

-script tells TTYtter you are running it in a script and therefor do not want introductory and courtasy output printed.
-notimeline tells it you don’t want to see your timeline.
-ssl tells it to use ssl, which is never a bad idea and probably mandatory for the api.

The if-clause makes sure that while TTYtter is collecting your new mentions the replies.txt file is not empty so as not to show a gap in Conky’s space on your desktop.

Now make the script executable:

$ chmod +x

Test the script:

$ ./readmentions
$ ls -l

Script showing Twitter mentions
Script showing Twitter mentions

A file called replies.txt should be created. Check its contents:

$ cat replies.txt

Your mentions should be in there.

Make sure this part works before continuing.

Install Conky

$ sudo aptitude install conky
$ cp /etc/conky/conky_no_x11.conf ~/.conkyrc

Run Conky and detach it from the current terminal so it doesn’t close when you close your terminal emulator.

$ conky -d

Customize Conky. It automatically reloads when you save the changed config file.
The config file is ~/.conkyrc. Add this to it:

${exec cat /home/test/.conky/replies.txt | fmt -w 40}

fmt -w 40 is the format command that wraps the lines somewhat intelligently at 40 characters.

Conky should show your mentions as soon as you save its config file.

Now we just need to schedule the script so it updates the replies.txt file periodically. Open your crontab:

$ crontab -e

Add this line to it:

*/5 * * * * /home/test/.conky/

Scheduling the script
Scheduling the script

Then save it. This will retrieve your mentions every five minutes. The following line will retrieve them every two minutes; the next every single minute:

*/2 * * * * /home/test/.conky/
* * * * * /home/test/.conky/

Smaller intervals aren’t possible with Cron; if you need near-realtime streaming try this instead:

$ TTYtter -vcheck -dostream -ssl


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.