Facebook Chat From the Command Line

I’m slowly trying to migrate my entire life into the command line. I realise that there are certain things that just can’t be done, like navigating the modern web, but most other things are possible. Today it was Facebook chat’s turn.

Prerequisite knowledge: Some command line fu, access to a Facebook account and a strong desire to be cool.

Facebook chat uses the Jabber/XMPP service. XMPP stands for “Extensible Messaging and Presence Protocol” and is based on XML. But we don’t need to worry about any of that, we’ll be using an XMPP client called mcabber.

mcabber

mcabber is a really cool piece of software that lets you communicate with an XMPP service from the command line. Installing it on a Debian based system like Ubuntu is really easy:

1
  $ sudo apt-get install mcabber

When you first start it up, it will complain about not being able to find a mcabberrc file. You need to create this yourself:

1
2
  $ mkdir ~/.mcabber
  $ touch ~/.mcabber/mcabberrc

But we won’t leave it blank, where’s the fun in that? There’s an example config file with settings and their explanations that can be found here. You’ll want to copy the full contents of that page and paste it into your newly created mcabberrc file.

It’s advisable to browse through the mcabberrc file to get a feel for what you can do. Once you’ve had a look, you need to set a few key options. At the top of the file, uncomment the lines that start with set jid and set password. You’ll need to set these two to your Jabber ID and password respectively. “What’s my Jabber ID?” I hear you ask. You can find out what your Jabber ID is from this Facebook page. Scroll down to the bottom and click on “Other”. There will be a field entitled “Jabber ID”. Use that.

Once you’ve filled in those two fields you’re actually good to go. Fire it up and have a look.

A few important things to note about mcabber usage. It has two modes: chat mode and “that other mode”. I spend almost all of my time in chat mode and you can get into that simply by pressing enter. To leave it, press escape. I haven’t been using mcabber that long so I’m not sure of the benefits of not-chat mode.

To scroll through your “roster”, also known as “buddy list” (it’s your list of Facebook friends on the left), you use page up and page down. If you receive a chat message you can press ctrl + q to go to the next unread message, then ctrl + x will take you to the last window you were at.

Scripting mcabber

mcabber is hugely customisable. You get that vibe from the mcabberrc file. The customisation that made my ears prick up was the chapter called “Scripting” in the mcabber User Guide. mcabber lets you call scripts for certain events. I decided to write a small script that alerts me when I receive new messages, just to play around with the functionality:

1
2
3
4
5
6
#!/usr/bin/env ruby

if ARGV[0] == "MSG" and ARGV[1] == "IN"
  `notify-send --category=im --icon=notification-message-im "#{ARGV[2]}" "#{File.read(ARGV[3])}"`
  File.delete(ARGV[3])
end

This script is in a file called ~/.mcabber/eventcmd, which is where I’ve configured my mcabberrc file to point for external commands. This just uses the built in notify-send command to tell me someone has said something and what they said. There’s plenty of documentation surrounding every aspect of mcabber, including how external scripts get called, it’s all well worth a read.

My finished setup

I’ll leave you with a screenshot of my workspace. If you have any questions, feel free to ask! :)

mcabber setup

Note that there is plenty of documentation on how to use mcabber, Google is your friend!

Comments