My personal webspace

A webspace for innovation, free thinking, and procrastination

This is a very quick post! I decided today to start putting a signature in my emails, which are sent by Thunderbird, and wanted to include a fortune (output from the fortune program, http://en.wikipedia.org/wiki/Fortune_%28Unix%29) into the footer of my signature.

Turns out that Thunderbird only allows you to add a static message, attach a file, or a v-card (not THAT v-card, silly you). So there’s no easy way to attach the output from a script.

BUT! It re-reads the file every time if you want to attach a txt file. So if there was a way to call a script every-time a file gets read… Enter inotify-tools, which includes a command called inotifywait which simply waits until a file receives a specified event. And then this script is born…

Script

#!/bin/bash

DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )

print_signature() {
    printf "Charles Hathaway\nRensselaer Polytechnic Institute\nComputer Science, PhD Student \n\ncharles@`hostname`:~$ fortune -s\n`fortune -s`\n" > $DIR/signature.txt
}

while true
do
    inotifywait -e access $DIR/signature.txt && print_signature
done

Pre-reqs

sudo apt-get install inotify-tools fortunes

Content © 2022 Charles Hathaway