Fun bits: Let the cow speak

While browsing the web for some new things to learn on Mac I found this funny tool that you can use on the terminal. It is called cowsay/cowthink.

Basically, it's just a script that generate an ASCII picture of a cow saying/thinking something. The message is user supplied and can be configured with some third party services which is what we will do later.

First, we need to install cowsay. I assume you have homebrew installed on your mac as it is the nicest way to install apps on it and the fact that homebrew is just plain awesome that anybody using Mac and CLI should have.

To install, open your terminal then type this script.

$ brew install cowsay

Try this script to make the cow say "hello".

$ cowsay hello

This will result to this image in your terminal.

cowsay ascii

cowsay ascii

Get messages from the web

We need a tool to make http request. For this, we will use wget.

For the source of our message, we will use this url http://whatthecommit.com/index.txt

In order to output the message to the console with wget, we will use the option -qO-.

The script would look something like this,

$ wget -qO- http://whatthecommit.com/index.txt

To make the cow say the message, we'll pipe the output to cowsay.

$ wget -qO- http://whatthecommit.com/index.txt | cowsay

You'll end up with this cow saying some random stuff. :)

cowsay some stuff

cowsay some stuff

Let the cow speak

Wouldn't it be better if the cow will keep on talking until you told it to stop? Let's work on that.

For this, we will use another tool which we could also install via homebrew. We'll use watch to periodically run the script we have above.

$ brew install watch
$ watch 'wget -qO- http://whatthecommit.com/index.txt | cowsay'

Run the script and have fun.