# Getting Random Things Done: fetching a random card from Trello

Published on

I am a big fan of randomness. Often when I struggle with a decision, be it what to have for lunch or how to name a baby, I pick a magic ball random number generator and do whatever it tells me.

Randomness is especially helpful in deciding what to do next. This is a decision we make many times a day, and it can consume a lot of mental energy.

In Getting things done, David Allen suggests a four-criteria model for choosing actions. Four criteria! That sounds like a lot of work in itself. Why don’t we delegate this decision to chance?

Since I use Trello as my GTD system, I developed a simple UNIX shell script to fetch random Trello cards from a particular list (such as “Next actions” or “To read”). If you would like to try it out, follow the instructions below.

## How-to

First, go to https://trello.com/app-key and copy the API key it generates. That page also has a link to generate a token “if you are looking to build an application for yourself” — and that’s exactly what you are doing. So go ahead and generate a token.

Save the API key and the token you’ve got to shell variables:

TRELLO_KEY=317130d1b90d72ac17ef53d59ba1bd81
TRELLO_TOKEN=65136e476c86f3688d33440acc7ba10681c9eb756e6557e78d119e28eec8e1bc

Next, you need to find out the id of the list you are interested in. Even the official docs admit that

One of the trickier parts of using the Trello API for simple use cases is finding a List ID that belongs to a user.

Follow their instructions to get the list id. Then create a shell variable to hold it:

TRELLO_LIST=a117f78b518937b5d958fcc8

Once you have the right data in the right variables, simply run the following pipeline in your shell prompt:

curl -Ns "https://api.trello.com/1/lists/$TRELLO_LIST/cards/open?key=$TRELLO_KEY&token=\$TRELLO_TOKEN" |
jq -r '.[] | "\(.name): \(.desc)\n" | @base64' |
shuf -n 1 |
base64 --decode

(The base64 encoding/decoding is needed to handle correctly descriptions that span multiple lines.)

You can put the above commands into a file and make it an executable script. For instance, I have scripts random-trello-action and random-trello-paper.